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.
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.
Compressing Multi Files Together
If you want to compress more than one file together, you can use 'cat' and gzip command with pipe command.
Look at the above snapshot, both the files ' file1.txt' and 'file2.txt' are compressed as 'final.gz'.
The 'gzip -l' command tells about the compression ratio or how much the original file has compressed.
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.
Look at the above snapshot, directory 'office' is compressed with 'tar' command.