tar archive - How is a single directory extracted without the parent directories?
Linux - SoftwareThis 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.
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.
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?
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.
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.
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.
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!
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.