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 11-06-2007, 01:47 AM   #1
JJV
Member
 
Registered: Aug 2003
Location: Canada
Distribution: Mandriva2005/Fedora4/Redhat 9 / mandrake 8/win2000 /win xp / Beos /
Posts: 39

Rep: Reputation: 15
Talking Tar Problems Some help please


Hi all

I hate to ask this because i think i am going to kick myself

So here goes I am working on a backup script and would like to be able to
extract a file and files with out the folders

so lets say a tar was made of /home/johnny/test/work how can i extract
this tar and NOT get (/home/johnny/test/work) but just the files in work.

every time i extract a file I get the tree structure also and I dont want that I just want the file's

I made a test, made two folders called it /test1 and /test2

in test1 I made 3 files test.txt test1.txt test2.txt I then made a tar with

tar -cvf /home/johnny/test2/test.tar /home/johnny/test1/ because I want the tar saved in test2

then I extract it back to test1 with tar -C /home/johnny/test1 -xvf /home/johnny/test2/test.tar witch works fine but it also makes the hole
(/home/johnny/test1) witch I dont want.

If someone can figure this out I would appreciated it very much

On a different note to everybody that is involved with Linux making,building,compiling, artists Mr Linus Torvalds for the kernel
and all of you people answering my petty questions

THANK YOU I TRULY MEAN IT THANK YOU ALL !! Linux is totally Amazing, build by you and me, Amazing !!! Have a blast of a day
 
Old 11-06-2007, 02:20 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Not sure it's what your after but..

On an individual file level, you could use -O:
Code:
tar -xvf /home/johnny/test2/test.tar /home/jonny/test1/test.txt -O > /home/jonny/test2/test.txt
This extracts the file test.txt passes it to standard output which we are redirecting to /home/jonny/test2/test.txt

This would only work for regular text files.
 
Old 11-06-2007, 02:25 AM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
If I'm reading correctly, does --strip-components work?

http://www.gnu.org/software/tar/manu...transform.html
 
Old 11-06-2007, 02:44 AM   #4
JJV
Member
 
Registered: Aug 2003
Location: Canada
Distribution: Mandriva2005/Fedora4/Redhat 9 / mandrake 8/win2000 /win xp / Beos /
Posts: 39

Original Poster
Rep: Reputation: 15
Talking Strip works

Thank you

billymayday and Disillusionist for your ansers it does look like

tar -xf usr.tar (--strip=2 )usr/include/stdlib.h works

just a though what if the tree has 5 folders down would it be strip=5
and so on seems logic

Thank you anyway it did help my script a long

JJV
 
Old 11-06-2007, 01:21 PM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Quote:
Originally Posted by billymayday View Post
If I'm reading correctly, does --strip-components work?

http://www.gnu.org/software/tar/manu...transform.html
Interestingly it's not a documented option in Ubuntu.

It works and it's listed in the output from
Code:
tar --usage
but the option is not shown in the man page (it is shown in the man page for tar in Centos
 
  


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 can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
installation problems with libxml2-2.2.66.tar.gz and libxml2-devel2-2.6.20-3.tar.gz g-string 3 Linux - Software 6 11-24-2005 11:39 AM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM

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

All times are GMT -5. The time now is 11:12 PM.

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