Wednesday 18 October 2017

bash - How can I extract only some specific folders from a tar.gz archive?


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


home  
-mike
-www
-coolwebsite
file1
file2
file3
etc.

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 ?



Answer



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


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...