Back to tools

find command builder

Choose conditions and an action to get a find command, every part explained, and see first which files it finds in a sample directory.

The command
find . -type f -name '*.log' -mtime +7

3 found

Where to look

. is the current directory; a path such as /var/log works too

Empty: no limit; 1: only what is directly in the starting point

Only its name, such as node_modules or .git; find will not go into it

Conditions

Empty conditions are not used; the ones filled in must all hold.

* is any characters, ? one character: *.log, report-??.txt

Sizes are rounded up to whole units before comparing

"Before 7 days" is -mtime +7, "in the last 7 days" is -mtime -7

Permission calculator

Octal, such as 644, 777, 4000 (setuid)

Then
Each part of the command
  1. find .Start in the current directory and search everything below it
  2. -type fOnly regular files
  3. -name '*.log'The name matches *.log: * is any characters, ? one character. The quotes make find, not the shell, expand the *
  4. -mtime +7Last changed more than 7 days ago. Whole days count: +7 is "over 7 whole days", so at least 8 days ago
Explain
Preview

Run in the simulator on the sample directory /home/user/project (whatever the starting point says); none of your files are touched.

3 found

./logs/app-2026-10.log
./logs/error.log
./logs/system.log
The sample directory

The directory the preview searches; the rows found are marked.

PathModeOwnerSizeChanged
README.md-rw-r--r--user1K3 days ago
notes.txt-rw-r--r--user030 minutes ago
backup.tar.gz-rw-r--r--user1.4M20 days ago
configdrwxr-xr-xuseryesterday
config/app.conf-rw-r--r--user8008 days ago
config/secret.env-rw-------user1204 days ago
logsdrwxr-xr-xuser45 minutes ago
logs/app.log-rw-r--r--user39K45 minutes ago
logs/app-2026-10.log-rw-r--r--user293K40 days ago
logs/error.log-rw-r--r--user09 days ago
logs/system.log-rw-r-----root5K12 days ago
node_modulesdrwxr-xr-xuser60 days ago
node_modules/libdrwxr-xr-xuser60 days ago
node_modules/lib/index.js-rw-r--r--user4K60 days ago
node_modules/lib/package.json-rw-r--r--user20060 days ago
scriptsdrwxr-xr-xuser5 days ago
scripts/deploy.sh-rwxr-xr-xuser6005 days ago
scripts/setup.sh-rwxrwxrwxuser90015 days ago
srcdrwxr-xr-xuseryesterday
src/app.js-rw-r--r--user2Kyesterday
src/Main.JS-rw-r--r--user3002 days ago
src/util.js-rw-r--r--user51210 days ago
tmpdrwxr-xr-xuser2 days ago
latest.log → logs/app.loglrwxrwxrwxuser1245 minutes ago
Good to know
  • Quote patterns: in find . -name *.log the shell may expand * to names in the current directory first, and the result is wrong.
  • Conditions are tested left to right; side by side they mean "and", -o means "or", ! means "not"; group with \( … \).
  • -mtime counts whole days: +7 is over 7 whole days (at least 8 days ago), -7 is within 7 days, 7 is the 7th day exactly.
  • Before deleting, run it without -delete and read the list; -delete goes after every condition.
  • -exec … \; runs once per file; -exec … + hands many files to one run, much faster.
  • Searching from /, add 2>/dev/null to drop the "Permission denied" errors.
Command reference: find