Let's say I want to compare the files with the same filename between these two directories:




It is required to sort them before comparing.

I am currently in the /tmp directory, and I tried to run this find with the exec option:

find datadir -type f -exec sdiff -s <( sort {} ) <( sort "/"{} ) \;

But, it gives me an error

sort: open failed: {}: No such file or directory

sort: open failed: /{}: No such file or directory

However, the below command works fine, but the data is not sorted for proper comparison.

find data -type f -exec sdiff -s  {}  "/"{} \;

How can I fix this problem?


The replacement of {} is done by find and happens after the evaluation of the process substitution (<(…)) and such in your code.

Using bash -c:

find datadir -type f -exec \
  bash -c 'sdiff -s <( sort "$1" ) <( sort "/$1" )' bash {} \;

Or to avoid running one bash instance per file:

find datadir -type f -exec bash -c '
  for file do
    sdiff -s <( sort "$file" ) <( sort "/$file" )
  done' bash {} +

You could consider using the -r (recursive) option that does all the sorting and recursing for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.