12

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.

18

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

  • 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 7 '16 at 21:52
3

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.