Fix ‘find: warning: you have specified the -maxdepth option after a non-option argument’

findshell

I have this bash command:

FILES=$(find $(dirname "$DIR")/**/**/*.js -type f -maxdepth 8 -not -path "*/babel/*" -not -path "*/examples/*");

I get this warning:

find: warning: you have specified the -maxdepth option after a
non-option argument -type, but options are not positional (-maxdepth
affects tests specified before it as well as those specified after
it). Please specify options before other arguments.

Anyone know what that's about? Google yield nothing. If there is anything else dubious about my command please lmk!

Best Answer

If you read the message it tells you that you have used -maxdepth after -type. The point is that -maxdepth is a global option (others include -xdev to avoid searches crossing mount points and -noleaf which stops find assuming that directories have standard unix link counts) and -type is part of an expression.

If you swap the order of -type f and -maxdepth 8 the message will go away.

Related Question