Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Untar file into a specific folder?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
0
0
GB
Hi. I have search hi-and-low for this. Google, Yahoo, Ask.com, looked at the official website for Tar, but still no luck.

Is it possible to extract *one* file from a .tar file, into a given directory, in the command. Something like;

`tar -xof /full/path/to/file.tar file.txt > /path/to/extraxct/to`

I'm ultimatly trying to do this with PHP, so its vital I can do it in one command :(

Cheers

Andy
 
tar xvf tarfile.tar filetoextract -C /path/to/extract

You can also use the Midnight Commander (mc) utility to extract single files from tarballs or RPM packages.



ChrisP
RHCE, LPIC-1, CCNA, CNE, MCSE, +10 others
 
Hi. Thanks for the feedback. However, it doesn't seem to be working for me :/ I tried this from SSH;

tar -xvf /home/linkssql/public_html/new/account/Thumb.tar Install.pm -C /home/linkssql/public_html/new/account/


Any ideas?

TIA.

Andy
 
Code:
cd /home/linkssql/public_html/new/account/
tar xvf Thumb.tar `tar tf Thumb.tar | grep 'Install.pm$'` -C .

maybe ...

what does:
tar tf Thumb.tar | grep 'Install.pm$'

give you?
 
Could this be run with one single PHP system() command though? As I originally said, I need it to do it in one command, otherwise I could just use;

cd /path/to/folder
tar -xof File.tar Install.pm

:-/

Cheers

Andy
 
What OS and version are you running? Try removing the - in front of xvf. It works fine on my Red Hat 9 box...


[root@nagios temp]# ls
nagiosconfigs.tar
[root@nagios temp]# tar xvf nagiosconfigs.tar cgi.cfg -C ./
cgi.cfg
[root@nagios temp]# ls
cgi.cfg nagiosconfigs.tar
[root@nagios temp]#


ChrisP
RHCE, LPIC-1, CCNA, CNE, MCSE, +10 others
 
what does:
tar tf Thumb.tar | grep 'Install.pm$'

give you?

it could be it wants the full path of 'Install.pm' rather than just the filename.
 
Example.
[root b]# touch a
[root b]# tar cvf a a.tar
[root b]# tar cvf a.tar a
a
[root b]# mkdir b
[root b]# tar xvf a.tar -C b/
a
[root b]# cd b/
[root b]# ls -tr
a
[root b]#


However


[root /]# tar cvf c.tar /tmp/c
tar: Removing leading `/' from member names
tmp/c
[root /]#
[root /]# tar xvf c.tar -C /tmp/b/
tmp/c
[root /]# cd /tmp/b/
[root b]# ls -tlr
total 32
-rw-r--r-- 1 root root 10240 Sep 1 12:56 a
-rw-r--r-- 1 root root 20480 Sep 1 12:56 a.tar
drwxr-xr-x 2 root root 14 Sep 1 12:57 b
drwxr-xr-x 2 root root 14 Sep 1 12:59 tmp[root b]# cd tmp
[root tmp]# ls
c
[root tmp]# pwd
/tmp/b/tmp



See tar is quite stupid sometimes so it won't give you the results you need all the time.

Enjoy !



 
You typed it wrong. The command is....

tar zxvf tarball.tar.gz /filetoextract -C /where/to/extract

An even easier way to extract files from a tarball or RPM package is using the mc (Midnight Commander) utility. I thought the utility was completely useless up until recently. Try it out, type 'mc' in a virtual console and then search for a .rpm or .tar.




ChrisP
RHCE, LPIC-1, CCNA, CNE, MCSE, +10 others
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top