Some notes on using Find on linux

Find by Name

Find Files

find . -type f

Find Directories:

find . -type d

Find Directories with a lot of files:

time sudo find . -type f -exec dirname {} \; | sort | uniq -c | sort -nr | head -50

cd to the directory you would like to search in

cd /home/ryan
find . -name pattern
find . -iname "<pattern>"
find ~ -iname "<pattern>"
find /etc/ -iname "<pattern>"

Find Files by Time

prior to 365 days ago:

find . -type f -mtime +365 -exec ls -haltr {} +

Find files 15 min ago until now

find . -type f -mmin -15

Between dates:

find . -type f -newermt 2016-10-05 ! -newermt 2016-10-08 -exec ls -haltr {} +

Delete stuff between dates, except for .zip and .7z files.

find /home/user/tempdirectory/ -type f ! -name '*.zip' ! -name '*.7z' -newermt 2010-01-01 ! -newermt 2017-01-31 -exec rm -v {} +

Find Older downloads and move them to “old” directory.

find /home/user/downloads/ -newermt 2010-01-01 ! -newermt 2017-07-31 -exec mv {} /home/user/downloads/old/ \;

Find files by size

find . -type f -size +500M
find . -type f -size +500M -exec ls -haltr {} +
find . -type f -size +500M -mtime +365 -exec ls -haltr {} +
find . -type f -size +500M -mtime +365 -exec rm {} +

Find files not named

find files not named .xva, .cfg, nor .dump
find /mnt/usb/*/ -maxdepth 2 -type f -not -iname *.cfg -not -iname *.xva -not -iname *.dump -exec basename {} \;

Alias Functions

function findhere { find . -iname $1; }
function findhome { find ~ -iname $1; }

Find and then ls with more information:

find . -name '*foo*' -exec ls -lah {} +

Other Resources