Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-19-2014, 04:35 PM
|
#1
|
LQ Newbie
Registered: Feb 2011
Posts: 21
Rep:
|
tar archive - How is a single directory extracted without the parent directories?
Data backups stored as *.tar.gz archice file. File system with many directory levels stored in the archive. Often only need to retrieve one directory from the archive. One directory that is a few levels deep in the directory heirarchy. Use command "tar -xzvf *.tar.gz dir-name" successfully to retrieve. But, extraction always returns the whole heirarchy. How is a single directory extracted without the parent directories?
|
|
|
01-19-2014, 11:13 PM
|
#2
|
Member
Registered: Sep 2010
Posts: 277
Rep:
|
well, i dont know exactly but i think there are ways you might be able to do this. by researching just a little there is a --wildcard flag which you could use. try something like tar -xf {tar ball name} --wildcards /pathtofile/*. so that should extract all files following a specfic path underneath a specific folder.
if you have an updated version of tar you should also be able to incorporate the --strip-components flag which if done right would not extract the upper parts of the heirarchy to a file.
|
|
1 members found this post helpful.
|
01-20-2014, 10:51 AM
|
#3
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
I don't think there's a way to do this. I created a tar with a few sub-directories and while I can perform tar -tvf <tarfilename> | grep <certain-sub-name>, it's going through the entire archive. More is the case that you can exclude placing files into the archive based on wild card, type of file, or via a cache tag (something I'm not sure I understand too well).
I think you would need to change tar source to do this. Tar is an archive tool and all it does is concatenate all the files and keep track of it to make a tape archive; which would be one continuous file to place on a tape backup. Zipping it is secondary. Therefore you'd have to create an argument to tar which would allow you unique control over the extraction and you'd need to control it such that it would say "ignore until you see condition A", "extract all which within condition A", "go back to ignoring unless you see condition A again"
Just tar a small set of files, two of them one in a subdirectory and one at your top level and view the tar file, you'll see what I mean by a continuous file. Don't zip it. Tar source is available, you'd just be playing with the extraction part of it. Something if once done successfully, you may wish to submit for inclusion in the next version of tar.
Last edited by rtmistler; 01-20-2014 at 10:52 AM.
|
|
1 members found this post helpful.
|
01-20-2014, 12:05 PM
|
#4
|
LQ Veteran
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Salix
Posts: 6,268
|
Have you tried the archive manager in the GUI, like Fileroller?
|
|
3 members found this post helpful.
|
01-20-2014, 12:08 PM
|
#5
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
Quote:
Originally Posted by DavidMcCann
Have you tried the archive manager in the GUI, like Fileroller?
|
Good one! Yep that works and should work for the OP too.
|
|
1 members found this post helpful.
|
01-21-2014, 06:01 AM
|
#6
|
LQ Newbie
Registered: Feb 2011
Posts: 21
Original Poster
Rep:
|
Will try to get Fileroller. Buíochas/Gratsias/Thanks baldur_1, rtmistler and DavidMcCann.
|
|
|
01-21-2014, 08:03 AM
|
#7
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
the c-line method goes like:
tar zxf file.tar.gz --strip-components=n
where n is the number of levels above the directory you wish to keep.
http://explainshell.com/explain?cmd=...s%3D1++-C+%2F+
|
|
|
01-21-2014, 10:01 AM
|
#8
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
Quote:
Originally Posted by Habitual
|
That one works as advertised, but I wonder about the selectivity. It seemingly doesn't explain what it's going to do, but it really does "strip". I tried it using --strip-components=1; and it removed the top-most level directory; extracting all below it. The issue there would be only if it were convenient for the extractor where they could get just the sub-directory they wanted. They may strip a few levels to get to the level they wish and then it also still extracts a bunch of parallel directories also at that same level, which they didn't wish to get.
|
|
|
01-21-2014, 10:47 AM
|
#9
|
LQ Veteran
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Salix
Posts: 6,268
|
Quote:
Originally Posted by Siopa
Will try to get Fileroller.
|
If you have Fedora with Gnome, you've got it. If you have KDE, there's an equivalent. Just click on the item in the file manager and see what it gives you.
The moral is that sometimes the GUI is actually quicker than the CLI, even if old-school Linux users tend to look down on it!
|
|
|
01-21-2014, 11:01 AM
|
#10
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by rtmistler
That one works as advertised, but I wonder about the selectivity. It seemingly doesn't explain what it's going to do, but it really does "strip". I tried it using --strip-components=1; and it removed the top-most level directory; extracting all below it. The issue there would be only if it were convenient for the extractor where they could get just the sub-directory they wanted. They may strip a few levels to get to the level they wish and then it also still extracts a bunch of parallel directories also at that same level, which they didn't wish to get.
|
I have to pause to verify what I'm actually doing every time I use it.
|
|
|
01-21-2014, 11:12 AM
|
#11
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
Whether it be highly complicated or patently obvious, I was interested to know whether or not this could be done via command line because it may be useful in a script. Then again, I should investigate if File Roller has a command line variation. I'm fine with using a GUI myself, and sounds like the OP is too. I did take a quick look at the manpage for my file-roller and it really is very minimal, allowing options for destinations mostly, but does allow for command line extraction.
|
|
|
01-22-2014, 03:21 AM
|
#12
|
LQ Newbie
Registered: Feb 2011
Posts: 21
Original Poster
Rep:
|
Found file-roller. Originally looked for fileroller, could not find. Found file-roller. The GUI program reads *.tar.gz file fast and easy from a DVD. Its a good solution. Will be using file-roller from now on. Buíochas/Gratsias/Thanks again.
|
|
|
01-22-2014, 03:49 AM
|
#13
|
LQ Newbie
Registered: Feb 2011
Posts: 21
Original Poster
Rep:
|
Apparently file-roller itself can be run from the command line. Use file-roller -h <archive name> to decompress the archive.
|
|
|
All times are GMT -5. The time now is 02:26 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|