I am trying to write a find command that finds both files and directories, the issue is that I get only files or an error depending on certain variables in the command.
This command outputs nothing at all:
find '/mnt/downloads/cache/' -depth -mindepth 1 \( -type f ! -exec fuser -s {} \; \) -o \( -type d -empty \) -print
This is because the two filters are not encapsulated in ( ). Why are double quotes needed?
This command outputs files only but not directories:
find '/mnt/downloads/cache/' -depth -mindepth 1 \( \( -type f ! -exec fuser -s {} \; \) -o \( -type d -empty \) \) -print
Extra set of brackets encapsulating the two arguments is the only difference.
The last variation of the command results in an error:
find '/mnt/downloads/cache/' -depth -mindepth 1 \( \( -type f ! -exec fuser -s {} \; \) -o \( -type d -empty {} \) \) -print
find: paths must precede expression: {}
Why does adding a second set of {} after diretory test results in this error?
Fixed command:
find "/mnt/downloads/cache" -depth -mindepth 1 \( \
-type f \! -exec fuser -s '{}' \; -o \
-type d \! -empty \) \
-print
-print
and-exec echo {}
? Why would you put the extra{}
after-empty
? AFAIK it doesn't take an argument, so that's why{}
is being parsed as a misplaced path. – steeldriver Dec 9 '17 at 13:43