Amazon Ads

Tuesday, October 13, 2020

find command

 To find abc* in current directory 

find . -iname abc*

To find abc* in /Downloads/ directory 
find /Downloads/ -iname abc*

Find files (f) in current dir and then feed it to grep({}) to see if it contains text with 'abc', and consequently print it.
find . -type f -exec grep "abc" '{}'\; -print

or

find . -type f -print | xargs grep "abc"

Find and delete the files (BE CAREFUL)
find . -iname "abc" -delete

Delete empty directories

find . -empty -type d -delete

find files and mention the size of each,
find Desktop/prova/ -iname "*.pdf" -exec du -hs {} \;

Find multiple files and remove them
find ~/Desktop/Junk/ -type f \( -iname "*.zip" -o -iname "*.jpeg" -o -iname "*.srt" \) -exec rm {} \;

count the files created in the last 1 min
find . -mmin -1 -type f -delete | wc -l

Delete all files created in the last 1 min
find . -mmin -1 -type f -delete

No comments:

Post a Comment

A trip to Buzios, Arraial do Cabo and Cabo Frio - Brazil

What a wonderful trip it was I must say. Of course, there were some downs as well, as expected. We started off with Buzios.  If you ever pla...