Posts tagged ‘find’

Find command – examples

Find command can do more than many of us could expect. Simple searches are obviously the most popular but as following examples show humble find can do a lot more:

1. search for a file
find . -name “filename”
2. don’t descend to other filesystems
find . -name “filename” -mount
3.list all directories
find . -type d
4. list all files
find . -type f
5. list all symbolic links
find . -type l
6. list all files more recent than filename
find . -newer filename
7. list all files that the userid doesn’t correspond to valid userid
find . -nouser
8. list all files that the groupid doesn’t correspond to valid groupid
find . – nogroup
9. search all core files and ask before deleting them
find / -name “core*” -ok rm rm{} ;
10. search all files and include the filenames in caution.txt
find / -perm 777 -fprint /tmp/caution.txt

11. search all .dat files bigger than 1M and older than 1 year
find /home -type f -name “*.dat” –size 1M -atime +365 -print
12. search all .c files and sort them
find /home -name “.c” -exec wc -l {} ; | sort -nr

For convienience I have created PDF version here.

March 20, 2008 at 10:45 am Leave a comment


Categories