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/username
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 {} +

Example: Zip files prior to 1 day

da=$(date --date="$daysago days ago" +"%Y%m%d")
echo "writing out zip file /Folder/ArchvieFile$da.zip"
find /folder/ -type f -maxdepth 1 -mtime +$daysago -exec zip --verbose --move /folder/ArchiveFile$da {} +

outputs a file /folder/ArchiveFile20190105.zip containing everything from a day or more ago, excluding zip files

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 {} +

File count by directory

find . -maxdepth 1 -mindepth 1 -type d -exec sh -c 'echo "$(find "{}" -type f | wc -l)" {}' \; | sort -nr

find . -type d -exec sh -c 'echo "$(find "{}" -type f | wc -l)" {}' \; | sort -nr | head -n20

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

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

Up next Kawasaki Vulcan S 650 Notes Now DMented Character Sheets Blot.im Book Notes Last updated: 2019-05-07 More now from other folks
Latest posts DMented 'zine for DM's and Character Sheets for Players Online Security Now Find Notes Kawasaki Vulcan S 650 Notes Honda Rebel 300 Notes Samba Notes Things worth noting My Software Friends Favorites Recommended Tech Elasticsearch Notes Book Notes APRS Notes vim notes Nmap Notes 4runner Notes Bash Notes Raspberry PI Zero quickstart Notes on Van Life Ubuntu 16.04 or 18.04 Installing Dropbox on Arch Linux Arch Linux Notes About Knives, Mainly Sharpening ENS Environment Notification System