Gossamer Forum
Home : General : Internet Technologies :

Extract a tar file into a specific folder?

Quote Reply
Extract a tar file into a specific folder?
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`

Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extract a tar file into a specific folder? In reply to
Hi,

You could probably do it with `tar`, but that's not as fun:

perl -MGT::Tar -le 'GT::Tar->untar("/path/to/tar/file", sub { return unless $_->name eq "file_you_want_to_extract"; $_->name("new/path/to/save"); $_->write; })'

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Extract a tar file into a specific folder? In reply to
Would this be ok to run via a PHP system() call?

Cheers Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Alex] Extract a tar file into a specific folder? In reply to
Hi. I just tried this, and it works *great*, BUT you have to be in a the 'admin' folder of a LSQL installation (to use GT::Tar) ... is there another module that will handle this, or a way I can call GT::Tar, without having to 'cd' first? As I stated earlier,I need to do this in one fail swoop, preferably with one PHP system() command.

FWIW, I'm trying to extract the Install.pm files out of my plugins (held in a directory), so I can pass them back into my plugins members area. The idea being they can see in real time the version numbers of the plugins.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extract a tar file into a specific folder? In reply to
Add

-I/path/to/links-sql/admin

just before the -MGT::Tar.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Extract a tar file into a specific folder? In reply to
Works like a charm.

No wonder you are where you are on the Internet today Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Alex] Extract a tar file into a specific folder? In reply to
Whoops...I think l just froze the server;

`perl -I/home/linkssql/public_html/cgi-bin/test/admin/ -MGT::Tar -le 'GT::Tar->untar("/home/linkssql/public_html/new/Thumb.tar", sub { return unless $_->name eq "Install.pm"; $_->name("/home/linkssql/public_html/new/Install.pm"); $_->write; })'`;

Unsure

Not sure if you are any good at PHP (you seem to be a man of many tallents...heh). What is the best way to run this command in PHP?

I tried it with a system() command, but that didn't work at all (didn't even seem to run, at least the Install.pm file wasn'tcreated).

Would exec() work for this kind of thing? I don't need any output returned... just need the file written to the folder in question.

TIA.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Extract a tar file into a specific folder? In reply to
Ah, you can do it the boring way to:

tar xvfO file.tar filetoextract > newfile

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Extract a tar file into a specific folder? In reply to
I give up :(

Tried using exec(), system(), `` and more... none of them work. I even tried creating a Perl script, and calling it via;

echo system("perl /path/to/script/update.cgi");

... it prints out the confirmation, but no file is generated! Eugh! I'm just gonna add another bit of info in the .php script, so that it knows what version its running.

Thanks anyway...

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!