The form you want almost every time is find /path -type f -name '*.txt': starting directory first, then the tests, pattern quoted so the shell cannot expand it first. Outputs below come from macOS 26.6 with BSD find; GNU find on Linux differs in -regextype, -size rounding and -O (cited from GNU find(1), not tested).
Below are the rules that decide whether it does what you meant or silently matches nothing. The symlink, -regex, -mtime, -size, -perm and leading-dash results below are checked by find-command-tutorial.sh on whichever find it runs under; a GNU-only claim it cannot test on that machine is reported as skipped, never as passed.
Table of Contents
find does NOT follow symlinks by default
This is the opposite of what many tutorials say. GNU on -P: “Never follow symbolic links. This is the default behaviour.” You do not need -P to be safe; you need -L to opt in. With a real directory sym/real and a symlink sym/link pointing at it:
default : sym sym/real
with -L : sym sym/link sym/real
Only -L descended through the link, which is where symlink loops come from. Placement matters too: GNU requires the five real options -H -L -P -D -O to “appear before the first path name”, and BSD rejects a late one:
$ find sym -P -type d
find: -P: unknown primary or operator
-name for filenames, -regex for whole paths
-regex is not a filename filter. GNU documents it as “a match on the whole path, not a search”, implicitly anchored at both ends, so a pattern anchored on the first letter of the filename can never match:
$ find documents -regex '^[aeiouAEIOU].*'
$
Zero results, always: every candidate path starts documents/. The working form:
$ find documents -regex '.*/[aeiouAEIOU][^/]*'
documents/Egg.gif
documents/orange.jpg
documents/apple.txt
The second trap is the dialect. GNU defaults to Emacs regular expressions, where ( and | are literal characters, not grouping and alternation; BSD defaults to POSIX basic, same result. Either way this matches nothing:
$ find documents -regex '.*\.(jpg|png|gif)$'
$
Three working forms:
find documents \( -iname '*.jpg' -o -iname '*.png' \) # portable
find documents -regextype posix-extended -regex '.*\.(jpg|png)$' # GNU only
find -E documents -regex '.*\.(jpg|png)$' # BSD/macOS
-regextype is GNU-only; BSD answers -regextype: unknown primary or operator. Unless you must match on path structure, -iname avoids both traps.
-mtime counts whole days and discards the remainder
-mtime n works in 24-hour units with the fraction discarded. With files aged 6, 7, 8 and 9 days:
$ find . -type f -name 'old_*' -mtime +7
./old_8d
./old_9d
+7 matched files 8 or more days old; the 7-day-old file was excluded. GNU states the rule under -atime: “any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.” For “at least a week”, write -mtime +6.
-size: the units are not what they look like
A bare number is not bytes. GNU lists “‘b’ for 512-byte blocks (this is the default if no suffix is used)” and “‘k’ for kibibytes (KiB, units of 1024 bytes)”. Use c for bytes. Tested against files of 1, 512, 513, 1024 and 1025 bytes:
-size 1 -> f_1 f_512 # one 512-byte block, rounded up
-size 1c -> f_1 # exactly one byte
-size 1k -> f_1024 # BSD: exactly 1024 bytes
That last line is where implementations split. BSD compares the scaled size exactly; GNU rounds up, so on Linux -size 1k matches every file from 1 to 1024 bytes and -size -1k matches only empty files. The GNU half is cited, not run here; find -size less than works through the same rounding with -1M. When size matters, use c: -size +1024c.
Finding world-writable files
-perm 0777 is an exact match on all nine bits, close to useless for a security sweep. With files at 0777, 0776, 0757 and 0644:
$ find . -type f -perm 0777
./p777
$ find . -type f -perm -o+w
./p757
./p776
./p777
The exact form found one file and walked past two equally world-writable ones. The leading dash in -o+w means “at least these bits”: the question you wanted to ask. Do not pair it with a blanket chmod 644, which strips the execute bit from every binary, script and directory matched. After a -print pass, clear only the offending bit with -exec chmod o-w {} +.
Deleting without regret
Preview, then re-run destructively:
find /tmp/build -type f -name '*.log' -print
find /tmp/build -type f -name '*.log' -delete
find /tmp/build -type f -name '*.log' -exec rm -f -- {} +
-- tells rm nothing after it is an option. find‘s output carries the starting path, so find . emits ./-rf and is already safe; a shell glob is not. With a file named -rf beside keepme.txt:
$ rm *
$ ls -A
-rf
rm read -rf as options, deleted the real file and left the decoy; the same glob breaks find itself with find: illegal option -- r. Prefer {} + over {} \;; it batches into fewer rm calls. If you pipe to xargs instead of using -exec, the same filename hazard returns in a worse form: without -print0 and xargs -0, a name containing a space arrives as two arguments, so rm can delete a file that was never selected.
A note on -O
-O is GNU-only (BSD: find: illegal option -- O) and its levels are not speed multipliers. GNU calls -O1 “the default optimisation level” and -O0 “Equivalent to optimisation level 1”, and says -O3‘s optimiser “is currently being evaluated. If it does not actually improve the performance of find, it will be removed again.” Any table giving these levels percentage gains is invented: -O1 cannot beat the default because it is the default. Real speedups come from searching less: -maxdepth and -prune.