Search code examples
shelldirectorytargnupg

Tar.gz and encrypt folders


I have a lot of folders I'd like to backup on a remote location. I'd like to tar.gz and encrypt all of these, [if possible] in a single command line.

So far, I've successfuly did half the work, with

find . -type d -maxdepth 1 -mindepth 1 -exec tar czf {}.tar.gz {} \;

Now I'd like to add an encryption step to this command, if possible using gnupg.

Can someone help?


Solution

  • No, you can't directly include multiple commands into -exec option of find.

    On the other hand, you can easily iterate over the results. For example in bash, you can do:

    find . -maxdepth 1 -mindepth 1 -type d | while read dir; do
      tar czO "${dir}" | gpg --output "${dir}".tar.gz.asc --encrypt --recipient foo@example.com
    done