Useful Find Tips and Tricks

Find Directories:

find / -name -type d find / -iname -type d (Ignore Case)

Find Empty Directories:

find / -type d -empty

Find and count the result :

find / -type d -empty | wc -l

Find and delete :

find / -type d -empty -exec rmdir {} ;

Find and count Not matching criteria (non empty in this case):

find . -type f -not -empty | wc -l

Find with multiple criteria :

find . ( -name ‘.txt’  -o  -name ‘.jpg’ )

Find based on size : ( larger than 10M)

find /home -type f -size +10485760c

( if the sign before the numbers is  – it means less than, without c  it will think that the size is in blocks, we can also use k for kilobytes )

Find and operate on the result :

We can execute a bash shell script on the find result . where $1 contains the filename


find /home -type f -size +10485760c -exec script_name

Find files by permission :

find / -perm -4000

** Find Excluding Certain Directories :**

find / ( -name EXCLUDE_DIR1 -o -name EXCLUDE_DIR2 ) -prune -o (  -type f -print \ )