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
daysago=1
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 {} +