Tar Directory

Jan 31, 2019 00:00 · 93 words · 1 minute read

To control the directory structure of your archive use the -C Option. tar changes into the specified directory and starts archiving right away. Files that should go into the archive should be specified relative to that specified archive.

So to archive a directory /home/user/foo/bar/go using tar cfj /home/user/foo/bar/go would let tar preserve the directory structure inside our archive. To just archive contents under go, preserving go in our archive, we have to tell tar to jump into /home/user/foo/bar/. From there on, we tell tar to archive go.

tar cfj newarchive.tar.bz2 -C /home/user/foo/bar go/

If you want to get in touch with me, send me an email

longo.tomas@googlemail.com