/errors/find/warning-global-option-maxdepth-after-argument
find: warning: you have specified the global option -maxdepth after the argument -name
- 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:
mkdir -p logs/old
touch logs/app.log logs/old/2025.log
find logs -warn -name '*.log' -maxdepth 1Output
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
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 fOutput
logs/app.log logs/old/2025.log
No warning, same result for the first command.
Which options are global
| Global option | Effect |
|---|---|
| -maxdepth N | descend at most N levels below the starting points |
| -mindepth N | skip results less than N levels deep |
| -depth | process directory contents before the directory itself |
| -xdev, -mount | do not descend into other file systems |
| -noleaf, -ignore_readdir_race | file 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.