Linux gzip Command:

Gzip command is used to compress the file in Linux system. When you see the structure of directory in recursive mode and if any file is specified as directory on command line then gzip will go down into directory and compress the file. Gzip command also reduces the size of named files via using the Lempel-Ziv coding. The extension of gzip files is .gz. Gzip turncuts the compressed file name if the file name is too long. Compressed files can be stored again into original form. Gzip save the compressed file with original name by default.

Install gzip and gunzip command:

You can use the gzip and gunzip command by simply install it on your Linux system. for install it on your system that is based on Febora, Redhat and CentOS machines use the given command.

Syntax:

yum –y install gzip gunzip

If your system is based on Ubunto and Debian machines then use the given commands.

Syntax:

apt –get install gzip gunzip

Example of gzip commands:

1. Compress Single File:

If you want to compress a single file inn Linux system then use the given command.

Syntax:

gzip myfile.txt

2. Compress the multiple File:

You can also compress the one or more file at same time in Linux system. if you compress multiple file then it will remove the original file then it compress into gzip file.

Syntax:

gzip myfile1.txt myfile2.txt myfile3.txt

3. Compressed file with original File:

You can also compress a single with keep the original file by create a copy of file.


Syntax:

gzip – c myfile.txt > myfile.txt.gz

4. Recursively compress File:

You can compress the all file in sub directories and directories recursively by using the – r option with gzip command.

Syntax:

gzip – r *

5. Decompress file:

You can decompress a single file via using the gzip command. And you can also use the gunzip command for decompress file.

Syntax:

gzip – d myfile.txt.gz

Or

gunzip myfile.txt.gz

6. Compression File Information:

If you want to see the information about all compress file then use the – l flag with gzip command. It lists the all information about compress and decompressed file.

Syntax:

gzip – l

7. Compression level:

You can apply compression level on file by using the gzip. You can specify the compression level as the value between 1 and 9. If you using the option 1 then it complete faster and if you are using the option 9 then it take longer time to complete.
Author
Jaishree
Views
2,656
First release
Last update
Rating
0.00 star(s) 0 ratings
Top