Find a file in directory where i know part of the filename and the extension - unix

I know the file im looking for begins with a data for example 20131111 and I know the file ends in .log, but I don't know the full file name,
what is a unix command that would allow me to see all files beginning with or containing this date and ending with .log.

Like this, for example:
find /certain/path -type f -name "20131111*.log"
-type f - just files.
-name "20131111*.log" files whose name starts with 20131111 and ends with log.

Related

Finding a file with a file format

I need to write a shell script to check if a file with specific file name format exists or not and if it exists need to archive. How can I look for that file. The format is totalload00n.txt. For eg totalload001.txt,totalload002.txt etc..Once I can find the latest file how can i extract the sequence number from the file and assign it to a variable.
Thanks
You haven't specified the OS but for Linux you would write
find . -type f -name "*.txt"
then it would display all files with the extension ".txt".

View files saved after specific date in unix

I try to open a group of files which were saved after a specific date using the following command
View /*/*log | grep 'Aug 30'
But I get a message as
Vim: warning : output is not to a terminal
And nothing happens.
Any suggestions???
You are effectively telling view to open all the log files. You then tell it to send its output not to the screen as normal, but to another command called grep.
You probably want to use find to generate a list of files and then tell view to open them. So, to find files changed yesterday (1 day ago), you could use:
find /wherever/the/logs/are -name \*.log -mtime -1
Now, you want to edit those files, so pass the list to view:
view $(find /wherever/the/logs/are -name \*.log -mtime -1)

How to rename file from the specific pattern within the file

I would like to change the file name according to the specific pattern within the file. Let's say I have the unique pattern that starts with "XmacTmas". I would like to use this pattern to rename the file with the additional character like "_dbp1".
Now my file name is "xxo1" and I want "XmacTmas_dbp1".
How can I do this in for thousands of files with some script.
Thanks
find . -name 'XmacTmas*' -exec echo mv {} {}_dbp1 \;
find the files of interest and execute command after replacing {} with the found filename.
Escape the ;. Without the \, find would take it as part of the command to execute.
If only files in the actual directory are needed, add -maxdepth 0 before -name (or any other of find's numerous options)
If the result is as needed, remove the echo

Use of find in unix on strange file/directory names [duplicate]

Im a beginner scripter, writing scripts in tcsh and csh(these are teached in my course)
Im writing a script which uses find for putting path of directories
this is the part of the script:
set list = (`find $PATH -type d`)
it works fine until the file or directory names arent named such as:
#fi##lename&& or −filename or :−,?!drectoryanem!-``
These special characters i couldnt handle i changed the find script to:
set list = ("`find $PATH -type d`")
bit none of these works, when i want to use the path from the list in this next script:
foreach i ($list:q)
foreach file (`find "$i" -maxdepth 1 -type f`)
....
end
end
it couldnt handle these special file names, so i get many errors like find: −."!filename: no such filename or directory
I worked it out
It had to be this way:
set subor = ("`find "'"$i"'" -type f -maxdepth 1`")
now it ignores everything in the filenames
and in:
foreach j ($subor:q)
i quoted it this way it ignores the white characters in file names

Get a list of files with full path

I would like to get a list of all the files in a directory hierarchy (like I would with ls -R), but such that instead of listing the name of the directory and its files beneath it, it would just output a list of files with their full path. Is this possible?
Use find for this type of thing.
find /home/me/subdir
will list all the files and directories, with full path, that live in /home/me/subdir.
find /home/me/subdir -type f
will only list files. (-type d for directories.)
If you need to match a filename glob, do like this:
find /home/me/subdir -type f -name "abc*"
Or exclude a file name pattern:
find /home/me/subdir -type f ! -name ".*"

Resources