Skip to content

/errors/find/warning-global-option-maxdepth-after-argument

find: warning: you have specified the global option -maxdepth after the argument -name

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · find (GNU findutils) 4.11.0updated
tool
find
exit code
0
versions
GNU findutils 4.x
os
linux, windows

GNU find prints find: warning: you have specified the global option -maxdepth after the argument -name, but global options are not positional... when -maxdepth comes after a test. The command still runs and gives the same result, because global options apply to the whole expression wherever they are written; find warns because the position suggests otherwise. Put -maxdepth right after the path: find . -maxdepth 1 -name '*.log'. The exit status is unaffected.

Reproduce the warning

GNU find enables warnings by default only when standard input is a terminal. The runner has no terminal, so this example turns them on with -warn:

bash
mkdir -p logs/old
touch logs/app.log logs/old/2025.log
find logs -warn -name '*.log' -maxdepth 1

Output

find: warning: you have specified the global option -maxdepth after the argument -name, but global options are not positional, i.e., -maxdepth affects tests specified before it as well as those specified after it.  Please specify global options before other arguments.
logs/app.log

Only logs/app.log is printed: -maxdepth 1 limited the search even though it was written after -name.

Fix: global options first

bash
mkdir -p logs/old
touch logs/app.log logs/old/2025.log
find logs -warn -maxdepth 1 -name '*.log'
find logs -warn -mindepth 2 -type f

Output

logs/app.log
logs/old/2025.log

No warning, same result for the first command.

Which options are global

Global optionEffect
-maxdepth Ndescend at most N levels below the starting points
-mindepth Nskip results less than N levels deep
-depthprocess directory contents before the directory itself
-xdev, -mountdo not descend into other file systems
-noleaf, -ignore_readdir_racefile system workarounds

Positional options such as -daystart, -follow, -regextype, -warn and -nowarn affect only the tests that come after them, so their place in the expression matters. Tests (-name, -type, -mtime) and actions (-print, -exec, -delete) are evaluated left to right.

Sources