Javatpoint Logo
Javatpoint Logo

Linux gzip

Gzip (GNU zip) is a compressing tool, which is used to truncate the file size. By default original file will be replaced by the compressed file ending with extension (.gz).

To decompress a file you can use gunzip command and your original file will be back.



Linux gzip Filters1

Look at the above snapshot, the gzip command has compressed the files 'file1.txt' and 'file2.txt'. Compressed files are shown with the extension (.gz). While gunzip command has decompressed the same files and extension (.gz) is removed.

gzip options

Compressing Multi Files Together

If you want to compress more than one file together, you can use 'cat' and gzip command with pipe command.



Linux gzip Filters2

Look at the above snapshot, both the files ' file1.txt' and 'file2.txt' are compressed as 'final.gz'.

gzip -l

The 'gzip -l' command tells about the compression ratio or how much the original file has compressed.



Linux gzip Filters3

Look at the above snapshot, command "gzip -l final.gz jtp.txt.gz" shows the ratio of both the files.

How To Compress A Directory

The gzip command will not be able to compress a directory because it can only compress a single file. To compress a directory you have to use 'tar' command.

Hyphen (-) is not mandatory in 'tar' command.

'c' is to create,

'v' is for verbose, to display output,

'f' to mention destination of your output file,

'z' for specifying compress with gzip.




Linux gzip Filters4

Look at the above snapshot, directory 'office' is compressed with 'tar' command.

Please Share

facebook twitter google plus pinterest

B.Tech / MCA

Learn Latest Tutorials