decrypt multiple OpenPGP files in a directory

user1815498 picture user1815498 · Sep 12, 2013 · Viewed 24.4k times · Source

I have several hundred gpg encrypted files in a directory, of the format filename.xyz.gpg where "xyz" is some arbitrary extension. I need to decrypt all of the files to generate filename.xyz decrypted in such a way that I don't have to manually enter the password for each file.

I have tried the following for directory "Testing":

for file in 'ls Testing'; do (echo <password>|gpg --passphrase-fd 0 -d $file 
--output     $file.decrypted);

I just wind up with a command prompt >, and nothing happens.

What is the matter with my syntax? Is there some more efficient way to do this without a bash shell loop?

Answer

dogbane picture dogbane · Sep 12, 2013

gpg can decrypt multiple files so you shouldn't need to write a loop.

Try the following. You will need to enter your password once.

gpg --passphrase-fd 0 --decrypt-files *.gpg