The command find is a powerful tool that can be used for many tasks that operate on a whole directory.
For example, you can find all files that were modified in your home directory in the last 30 minutes with the following use of the find command.
[amit@onyx docs]: find ~ -mmin -30 -print /home/amit /home/amit/.kde/share/config /home/amit/.kde/share/config/kdesktoprc /home/amit/.kde/share/apps/kalarmd /home/amit/.kde/share/apps/kalarmd/clients /home/amit/.Xauthority /home/amit/.viminfo /home/amit/public_html/teaching/handouts /home/amit/public_html/teaching/handouts/cs-linux.tex /home/amit/public_html/teaching/handouts/.cs-linux.tex.swp /home/amit/public_html/teaching/253/notes /home/amit/res/qct/pds/sect7/s7ods_orig.tex /home/amit/res/qct/pds/sect7/s7ods_hash.tex /home/amit/.amit-calendar.ics [amit@onyx docs]:
One of the most powerful uses of find is the ability to execute a command on all files that match the pattern given to find. Here are some examples:
find . -name "a.out" -exec /bin/rm -f {} \;
In the above we have to escape the semicolon so that the shell does not process it. Instead the find command needs to process it.
find ~ -name "*.c" -exec chmod -x {} \;
find ~ -name "*.[c|h]" -exec chmod -x {} \;
The expression *.[c|h] is an example of a regular expression. Regular
expression are a powerful way of expressing a set of possibilities. See man 7 regex for the full syntax of regular expressions.
find dir1 -type f -exec gzip {} \;
find dir1 -type f -exec gunzip {} \;