Link to home
Start Free TrialLog in
Avatar of Julian Parker
Julian ParkerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

URGENT! extract specific directory from gunzip | tar file

All,

I need to extract a directory from a tar.gz file in solaris 9 gtar not available.

I've used gunzip < file.tar.gz | tar xf - ./directory/* but it doesnt work. I'm more used to using tar with the -z option

I need the syntax urgently.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of endege
endege

gunzip -c /path/to/folder/filename.tar.gz | tar -xvf - path/within/archive/

-c writes the output produced (either the compressed or decompressed file) to standard output and leaves the input files unchanged. When multiple input files are specified, each file is compressed or decompressed independently before being written to the standard output. For better compression, you should concatenate all input file before compressing or decompressing them.

If tar has build-in support for gunzip you can just use:

tar -xzvf MyArchive Source_file
or
tar --extract --gunzip --verbose --file=MyArchive Source_file
Avatar of Julian Parker

ASKER

Cheers wmp, it seemed to be a bit temperamental, the command I used worked sometimes and not others... I eventually did; gunzip < file.tar.gz | tar xf - ./directory
Hi,
glad you found it!
As for the "sometimes not working ..." thing - I obviously didn't think twice about the asterisk in the directory parameter!
This will work only if the shell is able to expand it properly (i.e. to directories/files which exist locally as well as in the archive) .
So if your local ./directory is empty or non-existent, nothing will be extracted - the shell will leave the asterisk as is - and such a file /directory is not present in the archive!
Thx for the points anyway!
wmp