
Using option 9 will take longer to complete, however you will have the largest amount of space saved. Using option 1 will complete faster, but space saved from the compression will not be optimal. The level of compression applied to a file using gzip can be specified as a value between 1 (less compression) and 9 (best compression). In this example, a gzipped copy of the Linux kernel has compressed to 78.3% of its original size, taking up 121MB of space rather than 554MB. gz file such as the compressed and uncompressed size of the file as well as the compression ratio, which shows us how much space our compression is saving. With the -l or –list flag we can see useful information regarding a compressed. gz file as below.Īs mentioned in step 4, -d can be combined with -r to decompress all files recursively. Similar to example 3, it is possible to decompress a file and keep the original. To reverse the compression process and get the original file back that you have compressed, you can use the gzip command itself or gunzip which is also part of the gzip package.īoth of these commands will produce the same result, decompressing to file.txt, removing the compressed file. This can be reversed by running “gzip -dr *”, where -d is used to decompress and -r performs this on all of the files recursively. Upon running gzip with the -r flag over everything, all files were recursively compressed. txt files in the test directory which is our current working directory, there is also an example sub directory which contains example.txt. 1 root root 5 Jul 28 18:00 test]# gzip -r test]# ls -laRĭrwxr-xr-x. Newer versions of gzip may also have -k or –keep available, which could be used instead with “gzip -k file.txt”.Īll files within the directory and all sub directories can be compressed recursively with the -r test]# ls -laRĭrwxr-xr-x. You can instead keep the original file and create a compressed copy.gzip -c file.txt > The -c flag outputs the compressed copy of file.txt to stdout, this is then sent to, keeping the original file.txt file in place. Compress a single file and keep the original gzip -c file.txt > This will compress all files specified in the command, note again that this will remove the original files specified by turning file1.txt, file2.txt and file3.txt into, and file1.txt file2.txt file3.txt To instead compress all files within a directory, see example 8 below.ģ. Compress multiple files at once gzip file1.txt file2.txt file3.txt This will compress file.txt and create, note that this will remove the original file.txt file.gzip file.txtĢ.
#UNZIP GZ FILE LINUX INSTALL#


The compression technique can help you save a lot of memory by compressing. The below examples showing the process of compressing gzip and unzipping. Gzip has been around since May 1996 and is still widely used today. gz is used to compress a file in order to reduce disk space, it is quite popular in Linux and UNIX operating systems for this reason.
