Let's say I have the archive website.tar.gz, inside is the following folder structure :


When I extract the achive, it recreates exactly the same folder hierarchy (of course). I was hoping there was a way to extract for example only the "coolwebsite" folder to whichever folder I'm in at the moment.

So if I'm on my server in mydir/ and I extract website.tar.gz, I want the result to be the coolwebsite folder, without all the preceding folders. Is that possible ?


Just try this:

tar xvf tarfile --strip=4 ./home/mike/www/coolwebsite/*

should remove to 4 levels of directories (including ".")

EDIT: add option z (i.e. tar xzvf ...) if the input file is gzip'ed

  • 1
    This command didn't work for me with GNU tar 1.23 (Error: tar: ./Symfony/*: Not found in archive. It did work when I removed the ./ part from the path however. And yes, I can confirm that the top level directory inside the archive was named Symfony. Additionally I had to append the --wildcards option. Maybe this answer needs an update? – Hubro Apr 17 '13 at 16:06
  • It did not work for me. However, with GNU tar, the following switch worked for me: --strip-components=4. – Tristan Jahier Mar 31 '15 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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