I have been working with Unix for some years and have managed to learn a little bit of the find command, but I have always forget the syntax. That is why I am writing these lines to serve as a reminder as well as help for beginners.
Example 1: List all Python .pyc files in my current directory, including sub directories:
find . -name “*.pyc” -print
Notes:
- The wildcards after the -name flag must be wrapped in double quotes and
- Users who run BSD systems (including Mac OS X) can omit the -print flag
Example 2: Remove all .tmp files from my USB key (which is mounted at /Volumes/hai_usbkey), including those in sub directories:
find /Volumes/hai_usbkey -name ‘*.tmp’ -delete
Notes:
- We can wrap wildcards with single quotes
- The -delete flag tells the find command to remove the files. Please use this command with care since you cannot undo deletion
Tim Archer
April 7, 2007
Hi All! I also can never remember all the common options to the find command that I use. In case it help you can view my simple writeup at:
http://timarcher.com/?q=node/23
My writeup has one major difference than this blog post in that it describes how to use the execute option to pass the find results to another program (such as grep). Hopefully it helps someone!