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.
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.
An operational script system + a 30-function shared library + a 52-page field guide. The production layer the free snippets don't cover.
Get the Toolkit →Ten functions I source into every script on my own boxes — strict-mode setup, an ERR trap that names the failing line, lock and timeout wrappers, and cleanup that runs on every exit path. One email, no sequence.
intermediate · cleanup
Delete Old Log Files
Unmanaged logs fill /var/log until writes fail and services crash. find -mtime deletes .log files older than N days; preview with -print before deleting.
beginner · grep
Search Files for Text with grep
Opening files one by one to find a string wastes time. grep -rn searches every file under a directory and prints each match with its 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.