Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-maxdepth option after a non-option AND find: paths must precede expression

Tags:

linux

Hope someone can help with this:

Am trying to delete session files on /tmp with this command:

find /tmp -name 'sess_*' -user Username -maxdepth 1 $CMD {} \;

but I got these errors:

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

find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression]

I looked for solutions over the web but could not find any. I have deleted other tmp files with other commands and wonder if that affected some volume or socket.

Thank you in advance

like image 454
MFIHRI Avatar asked Sep 16 '12 01:09

MFIHRI


1 Answers

find has three types of options: options that are used to match files (e.g. -name, -user), options that specify actions to perform on the matched files (-print, -exec), and options that control the overall behavior of the command (e.g. -maxdepth, -xdev). The third type must be put before the other two. So it should be:

find /tmp -maxdepth 1 -name 'sess_*' -user Username -exec $CMD {} \;
like image 114
Barmar Avatar answered Oct 20 '22 10:10

Barmar