A simple batch encryption loop

Since I nailed down a way to encrypt files before transferring them over the Internet to a family member, I have been considering locking up a lot of the personal files I have on hand, in case they are lost or stolen. There are quite a few though, and the time it takes to step through the encryption process makes it inconvenient, to say the least.

gpg has a batch mode though, and splicing together the loop from this command and the encryption sequence from this command, plus a little help from gpg man page and elsewhere, I cobbled this together as a one-liner that appears to do the trick.

for nam in *.doc ; do echo MyPassword | gpg --batch -c --force-mdc --passphrase-fd 0 $nam ; done

The -c flag is the same as the --symmetric option, and the --passphrase-fd 0 flag accepts the password from whatever I type after entering the command … except that the echo fills that in for me. The --force-mdc option is only to avoid a warning message on the receiving end when it is decrypted, so you can omit that if you like.

I suppose it’s worth mentioning that I used detox to clean the file names a little bit beforehand; otherwise, spaces or oddball characters can interfere with the encryption command and cause the loop to halt. If you can improve upon this, by all means please let me know. I am well aware of my limitations as a script writer. :roll:

About these ads

2 Responses to “A simple batch encryption loop”

  1. 1 peterix 2010/02/05 at 10:51 AM

    Try adding quotes around the filename parameter for gpg. If I’m right, it will solve the problem with spaces.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Visit the Wiki!

Some recent desktops

May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF

May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games

Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers


This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,959,559 hits



Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: