4

I always extract this kind of files using on the route where I want those files:

# tar -xvf file.tar.bz2 

But it always creates a folder called "file" (for this example) and stores all inside it.

I've never had problem with that, but now I need to avoid that folder and simply extract everything in the route where I want all to be.

I've been reading the man tar (manual) .. but I still can't find an specific atribute that makes this.

How can I do that? (All in terminal)

1 Answer 1

4

tar does not create a folder called file; the folder file is stored in the tarball. This is because the tarball was creating with the command

tar cf foo.tar.bz2 foo

rather than

cd foo
tar cf foo.tar.bz2 .

According to man tar, you can use the switch --strip-components (--strip-path in older versions) to override this.

To strip a single leading folder, use this command:

tar xvf file.tar.bz2 --strip-components 1
2
  • Great! It worked perfectly! .. If I have more than a single folder inside the .tar file and use the --strip-components 1 what does it do? .. or can I specify which folder to unpack?
    – AAlvz
    Feb 10, 2013 at 3:26
  • 1
    It removes the first component of every file, i.e., foo/bar/baz will get extracted to ./bar/baz. If that's not desired, you have to use several tar commands. Before unpacking, you can execute tar tf file.tar.bz2 to see exactly where the files would get extracted.
    – Dennis
    Feb 10, 2013 at 3:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .