I can find the files I'm looking for with something like this:

find . -name "*.mp3";

What I want is something like this:

find . -name "*.mp3" -exec openssl enc -e -aes-256-cbc -in path/to/file.mp3 
-out path/to/file.enc -pass pass:pass;

But I have no idea how to reference the files which are found with find in the -exec portion of the command.

  • Use {}.­­­­­­ – roaima Jun 2 '15 at 23:17

You need to use {} to reference to your file. Hence:

find . -name "*.mp3" -exec openssl enc -e -aes-256-cbc -in "{}" -out "{}".enc -pass pass:pass \;
| improve this answer | |
  • For each output overwrite on the same file path/to/file.enc? And you'll need escaping {} and ;. – yaegashi Jun 2 '15 at 22:34
  • @yaegashi Corrected that. – shivams Jun 2 '15 at 22:36
  • @yaegash Neither quoting nor escaping {} is necessary. Try this: touch 'a b'; find . -name 'a b' -exec ls -l -- {} \;. Quoting is pointless anyway, since "{}" is expanded by the shell before find gets to see it. – lcd047 Jun 3 '15 at 5:59
  • @lcd047 Quoting is done in case the file names have spaces. – shivams Jun 3 '15 at 6:14
  • @shivams Quoting of {} is done automatically by find when building the command line for -exec. Please try the test I mentioned above. – lcd047 Jun 3 '15 at 6:21

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.