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 Samba Notes Attempting to connect to a windows share, on a domain, in kubuntu 18.04 and I encountered some issues. (Note: ran into this in CentOS7, ubuntu Online Security Some things you should be using if you happen to use the internet. I say should because I know of what I’m talking about. Been doing this a while.
Latest posts Recommended Tech 2022 Proxmox Notes Meow Wolf Financial Notes Cast a URL to a Chromecast Email List System Design Cards About Music, Finding the good stuff. Zines shirt designs Now Learning Graphical Design Python Notes Deploy to a Remote Docker registry DMented 'zine for DM's and Character Sheets for Players Online Security Find Notes Samba Notes Things worth noting My Software Friends Favorites Recommended Tech Elasticsearch Notes Book Notes APRS Notes vim notes Nmap Notes Bash Notes Raspberry PI Zero quickstart Ubuntu 16.04 or 18.04