LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-08-2008, 03:45 PM   #1
nyheat
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 75

Rep: Reputation: 15
Untar a particular directory from a tar.gz?


I'm trying to untar a particular directory from a tar.gz file

The command I'm using is tar xzfC file.tar.gz /stuff dir1/dir2/*


It works, but I end up with a nested directory: /stuff/dir1/dir2/files here

How can I make it so it unpacks the files directly into /stuff/ and not into /stuff/dir1/dir2..? Is it even possible?
 
Old 05-08-2008, 04:38 PM   #2
viron
Member
 
Registered: Dec 2005
Location: McKinney, Texas
Distribution: Slackware
Posts: 40

Rep: Reputation: 15
You can't.
 
Old 05-08-2008, 04:41 PM   #3
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Maybe something like this will do
Code:
tar -C /stuff -zxvf yourfile.tar.gz
 
Old 05-08-2008, 05:36 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by viron View Post
You can't.
You sure?

Code:
tar --strip-components=2 -C /stuff -zxvf file.tar.gz dir1/dir2/
 
Old 05-08-2008, 09:02 PM   #5
nyheat
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 75

Original Poster
Rep: Reputation: 15
Thanks colucix!

Do you guys know if it's possible to do it the other way around as well?

I'd like to create a tar from the /dir/dir/* files, but it's recreating the /dir/dir directories within the tar, all I want is the files.
 
Old 05-09-2008, 09:01 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by nyheat View Post
Do you guys know if it's possible to do it the other way around as well?

I'd like to create a tar from the /dir/dir/* files, but it's recreating the /dir/dir directories within the tar, all I want is the files.
What is the exact command you tried? Anyway, I think there is no need of such an option, since once you've extracted files in the directory /stuff you can simply do
Code:
tar -C /stuff -zcvf new_archive.tar.gz *
If you want to do the same in one step, you need tar version >= 1.15.91 and use the --show-transformed-names option, piping the output of the tar command to another tar command, as in
Code:
tar --strip-components=2 --show-transformed-names -C /stuff -zxvf file.tar.gz dir1/dir2/ | tar -C /stuff -T - -zcvf new_archive.tar.gz
However, my advice is: keep it simple!
 
  


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
How to untar all tar-files in a directory? zoomzoom Linux - Newbie 13 05-09-2017 11:52 AM
massive tar file, can't untar dtra Linux - Software 3 09-08-2011 04:32 AM
How to untar a file in another directory other then current directory. dr_zayus69 Linux - Software 8 05-16-2007 11:01 AM
Getting problem when untar the .tar.gz file? ramakumard77 Linux - General 2 11-29-2004 11:15 AM
Untar filename.tar.tar Dr.Swing Linux - Newbie 12 09-27-2002 07:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:33 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