find and grep command builder
Click together a find or grep command, see what every flag does, and preview before you delete anything.
Last updated
In short: find searches for files by name, size, age or owner: find . -type f -name '*.log' -size +100M lists log files over 100 MiB below the current folder. grep searches inside files: grep -r -i -n error . shows every line containing error, with its file and line number. Quote patterns, and always run a find without -delete first to see what it would remove.
Your input never leaves your browser. Everything is calculated on your device; nothing you type is sent to a server.
Find files by name, size or age
Search for text inside files
Review generated files before you use them. Provided as-is — see Terms.
How does the find and grep command builder work?
find and grep answer two different questions. find looks at files
from the outside: their name, size, age, owner and type. grep looks inside them, line by line, for a
piece of text. So "which log files are over 100 MiB?" is a job for find, and "which config file
mentions server_name?" is a job for grep.
A find command reads from left to right: first where to start, then the tests, then what to do with
each match. Every test must pass, so find /var/log -type f -name '*.log' -size +100M
means files, called something ending in .log, bigger than 100 MiB. Two details catch almost
everyone: quote the name pattern, or the shell fills it in before find ever sees it, and read
-mtime +N as "more than N whole days". The full list of tests is in
find(1).
grep prints every line that contains the text. Add -r to search a whole folder,
-i to ignore case and -n for line numbers. Without -F, the text
is a regular expression, where a dot means "any character"; with -F it is matched
exactly. All options are in grep(1).
Deleting with find is safe only when you look first. Run the command without -delete,
read the list, then add -delete at the very end. The builder gives you both commands in
that order, and refuses to delete without a filter.
Worked examples
Which files fill up my disk?
Input Files, bigger than 100 MiB, in /, hide permission errors, show details gives find / -type f -size +100M -ls 2>/dev/null
-size +100M means bigger than 100 MiB, -ls prints size, owner and date for each file, and 2>/dev/null hides the Permission denied lines from folders a normal user cannot read.
Delete backups older than 30 days, safely
Input Files named *.tar.gz in /srv/backups, 30 days or older, delete gives Preview: find /srv/backups -type f -name '*.tar.gz' -mtime +29
Then: find /srv/backups -type f -name '*.tar.gz' -mtime +29 -delete
Run the preview first and read the list. -mtime +29 means more than 29 whole days, so 30 days or older; the -mtime +30 found in many guides really means 31 days or older. -delete goes last, after all the filters.
Which config file sets this option?
Input Text server_name, in /etc/nginx, only *.conf files, ignore case, line numbers gives grep -r -i -F -n --include='*.conf' server_name /etc/nginx
-r goes through every folder below /etc/nginx, --include limits the search to .conf files, -F treats the text as plain text and -n prints the line number next to each match, so you can open the file at the right line.
Frequently asked questions
How do I find large files on Linux?
Run find / -type f -size +100M -ls 2>/dev/null. It lists every file bigger than 100 MiB with its size, and hides permission errors. Start in a smaller folder such as ~ or /var to make it faster, and use +1G for files over 1 GiB.
How do I find files modified in the last 7 days?
find . -type f -mtime -7 lists files changed less than 7 × 24 hours ago, below the current folder. For minutes instead of days, use -mmin -30 (the last 30 minutes).
Why does find -mtime +30 miss files that are 30 days old?
Because find counts whole days and drops the rest: a file 30.5 days old counts as 30 days, and +30 means more than 30. So -mtime +30 finds files at least 31 days old. Use -mtime +29 for 30 days or older.
How do I safely delete files with find?
First run the command without -delete and check the list. Then add -delete at the very end: find works from left to right, so find . -delete -name '*.tmp' deletes everything before it even looks at the name. When you skip folders with -prune, use -exec rm -- {} + instead, because -delete switches -prune off.
How do I search for text in all files in a folder?
grep -r -n 'text' /path searches every file below /path and prints file name, line number and line. Add -i to ignore case, -w for whole words, -l to list only the file names, and --exclude-dir=.git to skip a folder.
Why do I need quotes around *.log in find?
Without quotes, the shell replaces *.log with the matching file names in the current folder before find starts. find then searches for those exact names, or stops with "paths must precede expression". Quoted, find gets the pattern itself and matches it in every folder.