Extract .gz File in Linux to Another Directory

Last updated on Dec 27, 2019 in Linux

.gz is a compressed file created with Gzip. To extract files created with Gzip is straight-forward in Linux, but in order to extract the contents to another folder is little bit trickier. In Linux terminal, type:

$ gunzip -c your-file.txt.gz > folder/your-file.txt

The option -c tells the gunzip to output the contents to the standard output and to keep original file unchanged. Then we direct the output (decompressed content) to the target file folder/your-file.txt. Note, that the target folder must exists.