Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompress gzip file to specific directory [closed]

Tags:

What is the gzip equivalent of the following command:

tar xvzf /usr/local/file/file/file.tar.gz -C /usr/local/extract_here 

I am trying

gzip -d /usr/local/file/file/file.tar.gz -C /usr/local/extract_here 

but it does not work, how do I do that with gzip?

like image 317
gr68 Avatar asked Dec 04 '12 16:12

gr68


People also ask

How do I open a gz file without unzipping?

Just use zcat to see content without extraction. From the manual: zcat is identical to gunzip -c . (On some systems, zcat may be installed as gzcat to preserve the original link to compress .)

How do I use gunzip to a folder?

If you want to place it somewhere specific, create the directory ( mkdir /BIG5 ) and then extract the files into a file in there ( gunzip -c BIG5. gz > /BIG5/yourfile ). Related info: The > writes the output of a command into a file, never to a directory. So whatever is right of > will be a file.

How do I unzip a .gz file in Linux?

You can unzip GZ files in Linux by adding the -d flag to the Gzip/Gunzip command. All the same flags we used above can be applied. The GZ file will be removed by default after we uncompressed it unless we use the -k flag. Below we will unzip the GZ files we compressed in the same directory.


1 Answers

Given the fact that you have a .tar.gz file, the first way you tried, with the -C option, will work just fine:

tar xvzf /dir/to/file.tar.gz -C /dir/to/output/

tar calls gzip to decompress, and then extracts the files from the tar stream. gzip can only decompress, so gunzip file.tar.gz would simply leave with the decompressed file.tar, on which you would then need to tar xvf file.tar. The z option of tar is simply a shortcut to do the decompression with gzip along with extracting the files.

If you want to just decompress a .gz file (as opposed to extracting a .tar.gz file) to a different directory, simply pipe there. E.g. gzip -dc < file.gz > /somewhere/file.

like image 112
Mark Adler Avatar answered Sep 22 '22 00:09

Mark Adler