Header Ads

Breaking News

How to compress files on Linux 5 ways


There are quite a few commands on Linux for compressing files. One of the newest and most effective is xz, but they all have advantages for both saving disk space and preserving files for later use. In this post, we compare the compression commands and point out the significant differences.

tar

The tar command is not specifically a compression command. It’s generally used to pull a number of files into a single file for easy transport to another system or to back the files up as a related group. It also provides compression as a feature, which makes a lot of sense, and the addition of the z compression option is available to make this happen.

When compression is added to a tar command with the z option, tar uses gzip to do the compressing.

You can use tar to compress a single file as easily as a group though this offers no particular advantage over using gzip directly. To use tar for this, just identify the file as you would a group of files with a “tar cfz newtarfile filename” command like this:

$ tar cfz bigfile.tgz bigfile
            ^            ^
            |            |
            +- new file  +- file to be compressed
$ ls -l bigfile*
-rw-rw-r-- 1 shs shs 103270400 Apr 16 16:09 bigfile
-rw-rw-r-- 1 shs shs 21608325 Apr 16 16:08 bigfile.tgz

Note the significant reduction in the file size.

If you prefer, you can use the tar.gz extension which might make the character of the file a bit more obvious, but most Linux users will probably recognize tgz as meaning the same thing – the combination of tar and gz to indicate that the file is a compressed tar file. You will be left with both the original file and the compressed file once the compression is complete.

Copyright © 2020 IDG Communications, Inc.

Source Link

No comments