Corinna – a Mac user – likes working on the terminal but she never managed to find anything with it. She used to switch to OS X’s Finder for searching. Not anymore! She finally sat down to figure out find
and has assembled her favorite examples in this cheat sheet like 1-pager:
Are you a budding Product Owner? Check out our compilation "Skills for Successful Product Owners"
Sources:
- Excellent overview: http://www.tecmint.com/35-practical-examples-of-linux-find-command/
- http://javarevisited.blogspot.de/2011/03/10-find-command-in-unix-examples-basic.html
Content of the 1-pager:
look for “needle.txt” within the current directory & its subdirectories
find . -name “needle.txt”
ignore case, find “Needle” & “needle”
find . -iname “needle”
name contains “needle”; list only matching files
find . -type f -name “*needle*”
search everywhere; list only matching directories
find / -type d -name “needle”
additionally ignore all errors, such as “Permission denied”
find / 2>/dev/null -type d -name “needle”
check all .txt files whether they contain “needle”
find . -type f -iname “.txt” -print | xargs grep “needle”
same as above, but now it also works with filenames that contain spaces
find . -type f -iname “*.txt*” -print0 | xargs -0 grep “needle”
find all empty files in /tmp
find /tmp -type f -empty
remove all these empty files
find /tmp -type f -empty -print | xargs rm -f
files bigger than 50MB but smaller than 100MB
find / -type f -size +50M -size -100M
created during the last 50 days
find / -ctime -50
modified more than 90 minutes ago
find / -mmin +90
accessed during the last 24 hours but
not within the last hour
find / -atime -1 -amin +60
find all executable files
find / -perm /a=x
find files that don’t have 644 permissions
find / -type f ! -perm 644
find files with 777 permissions a nd change them to 755
find / -type f -perm 0777 -print -exec chmod 755 {} \;
find all PDFs owned by user “seamstress” (-group exists, too)
find / -user seamstress -iname “*.pdf”
Yohnnyjoe 2015/03/07
Awesome breakdown of find.
Corinna 2015/03/07 — Post Author
Thanks!
szestkam 2015/03/11
FIND is more powerfull tool but in this examples is show the most uses command, good job