Super Useful Linux Find Commands

The linux ‘find’ command is INCREDIBLY powerful. Here are some options/flags that I have found particularly useful. Obviously you can sift through the man page for find to figure everything out. I just wanted to list some here that I use often.

find ./ -name "filename.*"
find ./ -iname "fIlEnAmE.*"

These will search for files with the name “filename.*”. The difference is ‘iname’ is case insensitive while ‘name’ is case sensitive.

find ./ -mtime +30

This will search for files that have been modified 30 days before today

find ./ -user apache
find ./ -group apache

Find files owned by the user or group ‘apache’

find ./ -type f
find ./ -type d

Type “f” = files, type “d” = directories

find ./ -newermt "Feb 24"
find ./ -newermt "Feb 24" ! -newermt "Feb 28"

Find files modified after Feb 24, OR after Feb 24, but before Feb 28

find ./ -type f -exec chmod 775 {} \;
find ./ -type d -name "cache" -exec rm -rf {} \;

The “-exec” flag executes shell commands on each of the files found. The first example will look for all files in this folder (and all sub-folders) and chmod them 775. The second will find all directories named “cache” and delete them. The spacing of the “{} \;” is crucial.