export exc_lst='! -path  "/var/app/s2/pnl/incoming/recondata/*.*"';

When I try using the below find commands:

find $FILE_DIR -name "*.*"  "${exc_lst}" -type f -mtime +20 -user sh79790 -ls

it throws an error :Missing conjunction

find $FILE_DIR -name "*.*"  ${exc_lst} -type f -mtime +20 -user sh79790 -ls

it doesn't exclude the mentioned path.

When I pass the value directly, it works fine i.e.

find $FILE_DIR -name "*.*" ! -path  "/var/app/s2/pnl/incoming/recondata/*.*" -type f -mtime +20 -user sh79790 -ls

I need to resolve the variable which will have all the files to exclude from find command.

2 Answers 2


You have quoting problems.

Tip: stick an echo in front of the command line to see what it's actually expanding to. Even more explicit, for showing exactly where each argument is separated, stick python -c "import sys; print sys.argv[1:]" in front of the command line.

python -c "import sys; print sys.argv[1:]" \
    find $FILE_DIR -name "*.*"  "${exc_lst}" -type f -mtime +20 -user sh79790 -ls


['find', '-name', '*.*', '! -path  "/var/app/s2/pnl/incoming/recondata/*.*"', '-type', 'f', '-mtime', '+20', '-user', 'sh79790', '-ls']

As you can see, ! -path "/var/app/s2/pnl/incoming/recondata/*.*" is provided as a single big argument with spaces and quotes inside it. That's what you ask for when you quote ${exc_lst}": don't expand. find does not recognize this. It needs !, -path, and the path all as separate arguments.


echo find $FILE_DIR -name "*.*"  ${exc_lst} -type f -mtime +20 -user sh79790 -ls


find -name *.* ! -path "/var/app/s2/pnl/incoming/recondata/*.*" -type f -mtime +20 -user sh79790 -ls

As you can see, there are literal double quote characters around the pathname. It's going to exclude a path that literally contains those quotes, which won't occur.

Try defining exc_lst without those quotes:

export exc_lst='! -path  /var/app/s2/pnl/incoming/recondata/*.*'

and then using your second form:

find $FILE_DIR -name "*.*"  ${exc_lst} -type f -mtime +20 -user sh79790 -ls

Luckily, the path to exclude does not contain any spaces. If it did, you would have a much harder time of accomplishing this.

Note: All my sample output is missing the first argument to find because $FILE_DIR is not defined in my shell (you haven't specified its value) but if it were defined it would be there.

  • Thanks, but when i try to export the parameter without the single quotes and use it in the find command ,the * is expanded to actual name and find command fails: echo find /var/app/s2/pnl/incoming/ -name . ! -path /var/app/s2/pnl/incoming/recondata/OASYSFX_FOR_GENESISFX_orig.20150731 /var/app/s2/pnl/incoming/recondata/OASYS_FOR_GENESIS_orig.20150731.gz /var/app/s2/pnl/incoming/recondata/PASS2_POSTPROC....... Sep 16, 2015 at 12:38
  • @surajhebbar indeed — that's why you need the single quotes or backslashes around the asterisks or something
    – Celada
    Sep 16, 2015 at 13:44
  • 1
    Relying on the unquoted $exc_lst won't work if /var/app/s2/pnl/incoming/recondata/*.* matches a file (which is likely if the exclusion is useful). Sep 16, 2015 at 22:38

You cannot at the same time define exec_lst the way you did and prevent file name expansion by the shell.

-path and it's argument must be in separate arguments

So I recommend to use `-path* directly in the command line and only put the path into the shell variable.

Another way may be to omit the " around $[exed_lst] and add one or two backslashes before each star in the variable assignment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .