LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 01-19-2014, 04:35 PM   #1
Siopa
LQ Newbie
 
Registered: Feb 2011
Posts: 21

Rep: Reputation: 1
Question 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?
 
Old 01-19-2014, 11:13 PM   #2
baldur_1
Member
 
Registered: Sep 2010
Posts: 275

Rep: Reputation: 28
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.
Old 01-20-2014, 10:51 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
Old 01-20-2014, 12:05 PM   #4
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,142

Rep: Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314
Have you tried the archive manager in the GUI, like Fileroller?
 
3 members found this post helpful.
Old 01-20-2014, 12:08 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by DavidMcCann View Post
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.
Old 01-21-2014, 06:01 AM   #6
Siopa
LQ Newbie
 
Registered: Feb 2011
Posts: 21

Original Poster
Rep: Reputation: 1
Will try to get Fileroller. Buíochas/Gratsias/Thanks baldur_1, rtmistler and DavidMcCann.
 
Old 01-21-2014, 08:03 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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+
 
Old 01-21-2014, 10:01 AM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Habitual View Post
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+
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.
 
Old 01-21-2014, 10:47 AM   #9
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,142

Rep: Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314
Quote:
Originally Posted by Siopa View Post
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!
 
Old 01-21-2014, 11:01 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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.
 
Old 01-21-2014, 11:12 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 01-22-2014, 03:21 AM   #12
Siopa
LQ Newbie
 
Registered: Feb 2011
Posts: 21

Original Poster
Rep: Reputation: 1
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.
 
Old 01-22-2014, 03:49 AM   #13
Siopa
LQ Newbie
 
Registered: Feb 2011
Posts: 21

Original Poster
Rep: Reputation: 1
Apparently file-roller itself can be run from the command line. Use file-roller -h <archive name> to decompress the archive.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] command for tar'ing multiple sub-directories into a single tar file blainemiller Linux - Server 3 04-21-2011 02:05 PM
selectively tar based on date just the innermost directories of a single directory rsiazon Linux - Newbie 5 07-29-2009 12:15 AM
Restore a single file from tar archive lucktsm Linux - General 2 12-03-2006 01:57 PM
tar - extracting a single directory from a large archive? lowpro2k3 Linux - General 1 07-24-2005 02:44 AM
Tar including all parent directories? everythingand2 Linux - General 4 12-14-2003 06:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration