0

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.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

1 Answers1

0

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 \;
shivams
  • 4,505
  • 3
  • 19
  • 36
  • For each output overwrite on the same file `path/to/file.enc`? And you'll need escaping `{}` and `;`. – yaegashi Jun 02 '15 at 22:34
  • @yaegashi Corrected that. – shivams Jun 02 '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 03 '15 at 05:59
  • @lcd047 Quoting is done in case the file names have spaces. – shivams Jun 03 '15 at 06: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 03 '15 at 06:21
  • @lcd047 Oh. okay. Thanks for that. I didn't know that. – shivams Jun 03 '15 at 06:25
  • @lcd047 Thanks for pointing it out :) Good summary: http://unix.stackexchange.com/q/8647/116972 – yaegashi Jun 03 '15 at 06:30