bash gpg 仅加密文件夹中的某些文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/14247801/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gpg encrypt only certain files in a folder
提问by user1164061
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 :
一个文件夹里有15个文件,扩展名为gz。我只想加密其中的 12 个并跳过 3 个文件。有没有办法做到这一点?所有文件名都不同,可能以也可能不以相同的字母开头。目前正在做:
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;
假设文件名是 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?
我想用一个 gpg 命令加密除 alabama.gz 和 somename.gz 之外的所有文件;我怎样才能做到这一点?
回答by rsaw
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.
正如您已经知道的(根据您发布的内容),Bob 的回答是错误的说您不能使用单个命令加密多个文件。
You're almost there with your own command-line; you just need a little shell trickery, e.g.:
您几乎可以使用自己的命令行;你只需要一点shell技巧,例如:
gpg -r recip --encrypt-files $(ls $source/*.gz | egrep -v 'alabama|somename')
回答by Scott Meridew
Actually, you CAN encrypt multiple files with a single command if you want to encrypt ALL the files in the folder.
实际上,如果您想加密文件夹中的所有文件,您可以使用单个命令加密多个文件。
gpg -r 'name' --encrypt-files *.gz
Works just fine. Ryan's answer is correct if you want to skip those 2 files though.
工作得很好。如果您想跳过这两个文件,Ryan 的回答是正确的。
Scott
斯科特
回答by BellevueBob
You cannot encrypt multiple files with a single gpgcommand.  However, you could tarthem all into an archive and then encrypt the result.  See this similar questionon the UNIX site for more info.
您不能使用单个gpg命令加密多个文件。但是,您可以将tar它们全部放入存档中,然后对结果进行加密。有关更多信息,请参阅UNIX 站点上的这个类似问题。
In any case, you will need to list the files you want to include.
在任何情况下,您都需要列出要包含的文件。

