The style for this post is tabled by Terminal CSS
⌂ Home

Tar Directory

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/