Finding files
Finding files and executing commands on them
% find . -name "*.html" -exec rename .html .htm {} \;Find .html files in working directory and rename (just change the extension) to .htm. As you may be knowing, find works recursively in the subdirectories as well, the filenames are changed even in the subdirectories.
-exec option of the command is used to execute a command on the 'found' files by the preceeding part of the command.
{} is the name of the file. Just to simplify a bit, the second part of the command works like a loop. For each filename that is found, the command is executed.
All words after the command (to be executed with find) are arguments to it until an arument ';' is encountered. This needs to be escaped with a '\' as shown above.
Finding and Listing files
Get long listing of .htm files in reverse chronological order of their modification times. Webmasters may find this of great use.
ls -lt `find . -name "*.htm"`Note that command in the back-tics gets executed first and the output is passed to ls -lt
Find files in working directory which were modified in last two days
find . -mtime -2dot (.) can be replaced with name of the directory or path to get files of that directory
-ctime can be used to find files by their creation time
*.htm* can be replaced with the pattern of filenames you want to find
