Wall-Skills.com

Spread Knowledge with 1-Pagers – Agile & Scrum, Product Management, Facilitation, DevOps

The find command in examples

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:

[button link=”/wp-content/uploads/2015/02/find_command-Sheet_Wall-Skills1.pdf” type=”big” color=”orange” newwindow=”yes”] Get PDF [/button]

Did you know there are compilations of our 1-pagers? About Agile & Scrum, Facilitation and for Product Owners

Sources:

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”

Next Post

Previous Post

3 Comments

  1. Yohnnyjoe 2015/03/07

    Awesome breakdown of find.

  2. szestkam 2015/03/11

    FIND is more powerfull tool but in this examples is show the most uses command, good job

Leave a Reply

© 2023 Wall-Skills.com

Theme by Anders Norén