Search code examples
bashgnupg

gpg encrypt only certain files in a folder


There are 15 files in a folder, all with gz extension. I want to encrypt only 12 out of them and skip the 3 files. Is there any way to do this? all files names are different and may or maynot start with the same letter. currently am doing :

gpg -r 'name' --encrypt-files  $source/*.gz

Say the file names are apple.gz, alabama.gz, butter.gz, cake.gz, dog.gz, eagle.gz, oregon.gz, somename.gz;

I want to encrypt all files except alabama.gz and somename.gz with one gpg command ; How can I do this?


Solution

  • As you already know (from what you posted), Bob's answer is wrong to say that you can't encrypt multiple files with a single command.

    You're almost there with your own command-line; you just need a little shell trickery, e.g.:

    gpg -r recip --encrypt-files $(ls $source/*.gz | egrep -v 'alabama|somename')