GPG with tar.gz at the same time without the full path being packed

1

I would like to compress and encrypt a folder:

  • tar -cz "/path/to/the/folder/" | gpg --encrypt --passphrase "password" --recipient "mail@mail.mail" > "/destination/package.tar.gz.gpg"

When I decrypt and uncompress, it does not only contains the "folder" that I compressed, but has the full file path: /path/to/the/folder/[whatever]

I prefer avoiding the usage of cd, the absolute paths seems more clear to me.

How do I remove the full file path from the archive?

Gábor Dani

Posted 2015-08-21T07:40:47.387

Reputation: 141

see the tar -C dir option to effectively cd before tarring. – meuh – 2015-08-21T09:33:09.907

Answers

1

tar has different behavior, depending on whether you execute it from a folder not in the current path (for example, you tar something in /usr/local/src/foo, while being in your home directory /home/alice), where it will store the absolute path in the tar file. If you're in some folder in the path (for example, you want to tar /usr/local/src/foo while being in /use/local/src), it will use relative paths starting from the src directory.

If you do not want to actually change directory into the desired relative root directory, use the -C flag which virtually does so inside tar. These two are equivalent:

cd /path/to/the/folder; tar -cz *; cd $OLDPWD
tar -C /path/to/the/folder -cz /path/to/the/folder/

In case you wonder: $OLDPWD contains the last folder before cding into it.

Jens Erat

Posted 2015-08-21T07:40:47.387

Reputation: 14 141