Why does find -name *.log not work?
The shell expands *.log before find ever runs, so find receives a filename instead of a pattern. Quote it — find -name "*.log" — so find does the matching.
Quick Answer
The find command searches a directory tree for files matching tests you combine: -name for a quoted glob, -type f or -type d, -mtime for age in days, -size for size, and -path to include or exclude subtrees. The order of the expression is the program — find evaluates left to right, so an action like -delete or -exec must come after the tests that narrow the matches, or it runs on everything find walks. Two traps cause most accidents: an unquoted -name *.log is expanded by the shell before find sees it, so always quote the pattern; and the age sign is easy to reverse — -mtime +30 means older than 30 days while -mtime -1 means within the last day. This builder assembles the command with tests before actions, quotes patterns for you, explains every flag in plain English, and flags -delete and -exec as the destructive actions to preview with -print first.
Run this script on a real Linux server
Get $200 free credit — DigitalOcean
Get $200 Free →Affiliate link · we earn a commission
Need a domain for your next project?
Register with Namecheap — free WHOIS privacy included
Check Domain Prices →Affiliate link · we earn a commission
6 scripts + shared library + 52-page field guide. The production layer the free snippets don't cover.
Get the Toolkit →Why does find -name *.log not work?
The shell expands *.log before find ever runs, so find receives a filename instead of a pattern. Quote it — find -name "*.log" — so find does the matching.
What is the difference between -mtime +30 and -mtime -1?
+30 matches files modified more than 30 days ago; -1 matches files modified within the last day; a bare 30 means exactly day 30. Reversing the sign on a -delete job deletes the wrong files.
How do I delete files found by find without a mistake?
Run the command with -print first and read the list. -delete is an action and must come after the tests; placed before them it deletes everything find walks.
What is the difference between -exec command \; and -exec command +?
\; runs the command once per file; + batches many files into one invocation, which is faster and the right default when the command accepts multiple arguments.
intermediate · cleanup
Delete Old Log Files
Unmanaged log files silently fill /var/log until disk writes fail and services crash. find -mtime deletes .log files older than N days — preview with -print before removing from production.
beginner · grep
Search Files for Text with grep
Opening files manually to find a pattern across a codebase wastes time. grep -rn searches every file recursively and returns every match with filename and line number.
find . -name "*.log" -type f -print
. — Starts the search at . and walks every file and subdirectory beneath it.-name "*.log" — Keeps names matching the glob *.log. The pattern is quoted so the shell cannot expand it before find runs.-type f — Restricts matches to regular files only.-print — Prints each matching path on its own line (the default action). Safe to run.