Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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
share|improve this answer
    
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 '13 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 '13 at 3:36
    
Ok, I'll check those. Thank you! –  AAlvz Feb 10 '13 at 3:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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