18

Example command:
$ tar -cvjf destination.tar.bz2 /path/to/folder/source

I'd like the final destination.tar.bz2, when extracted, to not include a /path/to/folder/ file directory. It seems inefficient to extract the tarball and then mv the contents of /path/to/folder/source to a different directory.

bottles
  • 389
  • 1
  • 2
  • 11

2 Answers2

22

tar -C /path/to/folder -cvjf /path/for/acrhive.tar.bz2 source

-C (uppercase) means 'change directory', so your file specification becomes relative to the path provided with -C

thinice
  • 4,716
  • 21
  • 38
  • Bear in mind that the path you provide for "source" is relative to the "-C". Like, that's what @thinice wrote, it's just that if you still provide an absolute path instead of relative even when using "-C", you don't get the desired result. – GuyPaddock Dec 07 '16 at 21:52
5

There are many ways to accomplish that, but this is probably the simplest:

cd /path/to/folder
tar -cvjf /past/to/destination.tar.bz2 source
Chris S
  • 77,945
  • 11
  • 124
  • 216