Examples of executing commands with the find command

To remove several files:

   find . -name 'mtg_*' -print -exec rm {} \;

This will search for and remove all files starting with the expression mtg_ from the current directory and its subdirectories.


To find and remove specific files:

   find . -name '*.tmp' -ctime +30 -print -exec rm {} \;

This removes all files in the current directory and its subdirectories with the filename extension .tmp which have not been changed within the last 30 days.


To find and remove files interactively;

   find ~/Docs -name '*.ps' -print -ok rm {} \;

This searches for files with the extension .ps starting in the subdirectory "Docs" in the user's home directory. Each time a file is found that matches this expression, the user is prompted to confirm that they want to remove it.

Entering y removes the file.


[Home] [Search] [Index] This site maintained by unixhelp@hardrock.org