SysadminGuide

How to find files with find on Linux

On this page
  1. Find by name
  2. Filter by size or age
  3. Act on the results, carefully
  4. Other handy filters

To find files on Linux, find is the tool, and the shape is always the same: find, then where to look, then what to match. find . -name '*.log' lists every .log file under the current folder; swap the dot for /var/log to search there instead. From that base you filter: -type f for files or d for directories, -size +100M for the big ones, -mtime -7 for things changed in the last week. Then you can act on the matches with -delete or -exec. It ships on every Linux and macOS system. Here's the everyday syntax, the filters you will actually use, and the safe way to delete matches without wiping the wrong thing.

The short answer

find . -name '*.log' lists matching files below the current folder. Filter with -type, -size and -mtime, then act with -delete or -exec. Always run it without -delete first to check the list.

-namematch by name
-size / -mtimeby size or age
-deleteact on matches
Answer card showing find . -name to locate files, filtering by type, size and mtime.
Where to look, what to match, then what to do. That is the whole shape of find. PNG

Find by name

Linux
find . -name '*.log'

That walks the current folder and everything under it. Use -iname for a case-insensitive match.

Filter by size or age

Linux
find /var/log -name '*.log' -mtime +30

Hunting for what is eating your disk? Match on size and files only:

Linux
find . -type f -size +100M

Act on the results, carefully

Linux
find . -name '*.tmp' -delete

Run it once without -delete and read the list first. find does exactly what you say, including deleting a tree you did not mean to.

Terminal showing find by name listing log files, find with -mtime for old logs, then find with -delete.
List, narrow, then act. The -delete goes on last, after you trust the list. PNG

Other handy filters

-type d for directories, -empty for empty files or folders, -newer ref for anything modified more recently than a reference file, and -exec command {} + to run a command on every match when -delete is not what you need.

Frequently asked questions

How do I find a file by name?

find . -name '*.conf' lists every .conf file under the current directory. Use -iname instead of -name to ignore case. Keep the quotes around the pattern so the shell does not expand the star before find sees it.

How do I find files bigger than a certain size?

Use -size with a suffix: -size +100M for larger than 100 MB, -size -1k for smaller than 1 KB. Combine it with -type f so you match only files, not directories.

How do I find files changed recently?

Use -mtime in days: -mtime -7 means modified in the last 7 days, -mtime +30 means older than 30 days. For minutes rather than days, -mmin works the same way.

How do I delete the files I found, safely?

Run the find without -delete first and read the list. Only when it is exactly right, append -delete (or -exec rm to act on each one). Deleting blind is how people erase the wrong tree, so always look before you add -delete.