16

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.

1

2 Answers 2

21

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

1
  • 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, 2016 at 21:52
4

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
1
  • I'm partial to 'cd /path/to/folder && tar cjf /path/to/destination.tar.bz2 source' Nov 30, 2020 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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