infoLinux

Linux gzip command options

Gzip (GNU zip) is a compressing tool. Which is use to truncate the file size. Original file will be replace by the compressed file ending with extension (.gz) with by default.

Now you can use gunzip command for decompress and your original file will be back.

Sample syntax of gzip command :

# gzip <file1> <file2> <file3>. . .   # gunzip <file1> <file2> <file3>. . .

Like example of gzip command :

# gzip file1.txt file2.txt  # gunzip file1.txt file2.txt

See your terminal after run the command, Linux gzip command has compressed the files ‘file1.txt’ and ‘file2.txt’. It compress files are shown with the extension (.gz). Command gunzip command has decompress the same files and extension (.gz) is remove.

gzip command options

Compressing Multi Files Together

When you want to compress more than one file together, you can use ‘cat’ and gzip command with pipe command.

Sample syntax of gzip multiple command :

# cat <file1> <file2>. . | gzip > <newFile.gz>

Like example of gzip multiple command :

# cat file1.txt file2.txt | gzip > final.gz

After run the command on your terminal and see, both the files ‘ file1.txt’ and ‘file2.txt’ are compresse as ‘final.gz’.

gzip -l command options

Unix and Linux gzip -l command tells about the compression ratio or how much the original file has compressed.

Sample syntax of gzip multiple command :

# gzip -l <file1> <file2>. .

Like example of gzip multiple command :

# gzip -l final.gz jtp.txt.gz

See your terminal after run the command, command “gzip -l final.gz jtp.txt.gz” shows the ratio of both the files.

How To Compress A Directory

Unix and Linux gzip command will not be able to compress a directory because it can only compress a single file. Now you can compress a directory you have to use tar command.

Hyphen (-) is not mandatory in ‘tar’ command.

‘c’ – It is to create,

‘v’ – It is for verbose, to display output,

‘f’ – It mention destination of your output file,

‘z’ – for specifying compress with gzip.

Sample syntax of gzip multiple command :

# tar cf – <directory> | gzip > <directoryName> or# tar cvfz office.tar.gz office

Like example of gzip multiple command :

#tar cf – office | gzip > office.tar.gz

If you understand both command and their options.Now you can practice more and more. Then you can achieve expertness. Thank you .

Leave a Reply

Your email address will not be published. Required fields are marked *