tips
46 tips Find
One command, setting or habit at a time about Find: what it does, the line to copy and a caveat or two.
find 24
-
Selects files that sit on a given filesystem type, and -printf %F shows which type that is.
find / -maxdepth 1 -fstype proc -
Uses a command's exit status inside find to keep only the files that fail a check.
find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null -
Changes find's order so files come before their folder, which some copy and delete jobs need.
find /srv/data -depth -print -
Sorts search results into separate files without walking the folder tree twice.
find /srv/archive \( -name '*.txt' -fprint txt.list \) -o \( -name '*.gz' -fprint gz.list \) -
Moves all the files find selects into one folder with a handful of mv calls instead of one per file.
find /srv/app -name '*.log' -mtime +30 -exec mv -t /srv/old-logs {} + -
Runs a few commands per file from find, with the file name passed safely.
find . -name '*.txt' -exec sh -c 'for f; do cp -- "$f" "${f%.txt}.bak"; done' sh {} + -
Shows which folders hold the most files, for finding the place with a million cache files.
find /var -xdev -type f -printf '%h\n' | sort | uniq -c | sort -rn | head -
Makes find search inside folders that are reached through symbolic links.
find -L /srv/media -name '*.mkv' -
Feeds a long list of starting folders to find from a file instead of the command line.
find -files0-from dirs.list -name '*.log' -
Prevents the shell from expanding a wildcard before find gets to see it.
find: possible unquoted pattern after predicate `-name'? -
Gives you paths relative to the folder you searched, ready for another command.
find /srv/site -type f -printf '%P\n' -
Removes a file with a strange name by its inode number instead of its name.
ls -i -
Runs a command from the folder of each matched file, so output lands next to it.
find /mnt/user/downloads -name '*.zip' -execdir unzip -n {} \; -
Looks up files by name in a prebuilt index instead of walking the whole disk.
sudo apt install plocate -
Asks for a yes or no before find runs a command such as rm on each file.
find ~/Downloads -name '*.iso' -ok rm {} \; -
Makes find stop at the first matching file instead of searching the whole folder tree.
find /mnt/user -name 'docker-compose.yml' -print -quit -
Deletes the files that match your tests, as long as -delete comes last in the command.
find . -name '*.tmp' -delete -
Passes file names between find and xargs safely, even with spaces or quotes in them.
find . -name '*.tmp' -print0 | xargs -0 rm -- -
Runs a command on batches of matched files instead of once per file.
find . -name '*.py' -exec grep -l 'TODO' {} + -
Lists files that belong to a user or group id nobody uses.
sudo find / -xdev \( -nouser -o -nogroup \) -ls 2>/dev/null -
Lists files and folders in which the others class has write access.
find /var/www -perm /o+w ! -type l -
Lists every file that runs with the rights of its owner.
sudo find / -xdev -type f -perm -4000 2>/dev/null -
Skips a whole directory tree during a search, such as a dependency folder.
find . -name node_modules -prune -o -type f -name '*.js' -print -
Lists the files that were modified within the last number of minutes.
find /etc -type f -mmin -30
Filters 12
-
Shows all the names a file has on disk, so you know what still keeps it alive.
find /srv -xdev -samefile /srv/downloads/movie.mkv -
Lists the files that belong to one user, for a cleanup or before you remove the account.
find / -xdev -user olduser -ls 2>/dev/null -
Lists the symbolic links that point to a certain path, for example before you move a folder.
find / -xdev -lname '/mnt/olddisk/*' -ls 2>/dev/null -
Lists folders and symlinks together without writing two type tests joined with -o.
find /srv -maxdepth 1 -type d,l -
Explains why find with two -name tests and -print shows only one kind of file.
find . -name '*.txt' -o -name '*.log' -print -
Lists the files the current user can actually execute, instead of guessing from permission bits.
find ~/bin /usr/local/bin -type f -executable -
Finds files by name while ignoring upper and lower case, so .JPG and .jpg both match.
find /mnt/user/photos -iname '*.jpg' -
Lists symbolic links whose target no longer exists.
find /srv /etc -xtype l -ls -
Filters out whole folders from the result by matching the full path.
find . -type f -name '*.php' -not -path '*/vendor/*' -not -path './.git/*' -
Matches file paths with one regular expression instead of several -name tests.
find . -regextype posix-extended -iregex '.*\.(jpe?g|png|gif)$' -
Limits how many directory levels find goes down.
find /etc -maxdepth 1 -type f -name '*.conf' -
Lists empty files and empty directories under a path.
find . -mindepth 1 -type d -empty
Time and size 10
-
Lists files between two sizes, for example everything between 100 MB and 1 GB.
find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + -
Finds files whose owner or permissions changed recently, even when their content did not.
find /etc /var/www -ctime -1 -ls -
Makes find's day tests start at midnight, so yesterday means yesterday on the calendar.
find /var/log/app -daystart -type f -mtime 0 # changed today -
Shows why searching for files nobody read lately with find gives misleading results.
find /srv/share -type f -atime +365 -
Explains why small files go missing from a find -size search, and how to fix it.
find . -type f -size -1024k -
Prints byte sizes and paths so you can sort and find the largest files.
find /srv -type f -printf '%s\t%p\n' | sort -nr | head -n 10 -
Lists large files on one filesystem so you can see what is filling it.
sudo find / -xdev -type f -size +500M -exec ls -lh {} + -
Lists the files modified inside a date range, without a reference file.
find . -type f -newermt '2026-11-01' ! -newermt '2026-11-08' -
Lists the files modified after the moment of a reference file.
find /etc -type f -newer /tmp/before-upgrade -
Explains how find rounds ages in days and how to get a finer cut-off in minutes.
find /backup -type f -mtime +7 -print
Nothing in this filter yet.