From LQWiki
find is a tool which allows primarily for the searching of files in a directory hierarchy. It allows for versatile search criteria, for formatted output, and for custom commands to be run on search-results
Examples
List all files fully qualified (e.g. /etc/services instead of services)
tweedleburg:/ # find . ./.vmware ./srv ./srv/ftp ...
If one wants to find and delete all old backup files from your vi or emacs edit sessions, but save directories that happen to end in a tilde
As root:
find / -type f -name "*~" -exec rm {} \;
That's it. Another example, if you wanted to perform a simple recursive grep:
find . -exec grep -H "searchtext" {} \;
Find all non-empty files:
find -not -empty
Find also works well with xargs. Using xargs minimizes the number of times that grep or rm is run, speeding things up. The last commands could have been:
find / -type f -name "*~" | xargs rm find | xargs grep "searchtext"
From the current dir down
find . -type f -ctime -3 -exec ls -l {} \;
for the last 72 hours
find . -daystart -type f -ctime -3 -exec ls -l {} \;
To delete all files with the name dummy in tmp try
cd /tmp;find ./ -name 'dummie*' -exec rm -f \{\} ';'
To count the rows of all your files in the current directory use
find | xargs cat | wc -l
External links
- find man page
- findutils web page (www.gnu.org)

This page is available under a