How to compress file in linux using tar

By | January 5, 2015

Data compression has been useful to us in recent years whether its for saving some free disk space or to save and backup valuable data that stored on a server, with compression we will make the downloading progress easier, because you just need to download one file to download the whole files and that file were called archive.

Both Linux and Unix has various commands for Compress a file, to compress a file you can use bzip, zip, gzip and tar or in Windows maybe you are familiar with rar ? winrar ? but In this quick tutorial I will try to show you how to compress file in Linux using tar. Tar is a very commonly used archiving utility on Linux system. The good about tar is that it just use very little CPU resource to compress a file. Tar is probably the Linux version of Zip.

So how to compress file in Linux using tar ? here’s how.

Compress Single File

Its really simple to compress 1 file you just need run this command :

$ tar -cvf archive_name.tar file1.txt
How to compress file in linux using tar - 1

How to compress file in linux using tar – 1

On the screenshot we know that the archive is on the current working directory, to change the output directory just change the command a bit like this.

$ tar -cvf directory/archive_name.tar file1.txt
How to compress file in linux using tar - 2

How to compress file in linux using tar – 2

Did you noticed the option ? there are “c“, “v“, and “f” options, here is some explanation about those options :

c = is option to compress the file or create a new archive.
v = means verbose, option that commonly used to display a list of the files that were included in the archive.
f = is used to archive a file or device.

Compress Multiple Files

To compress multiple files you just need to modify the first command just a little bit.

$ tar -cvf archive_name.tar file1.txt file2.txt

If you want to add more files to the tar archive simply just type the file you want to add and use space as the separator between those files.

How to compress file in linux using tar - 3

How to compress file in linux using tar – 3

So that is how to compress file in linux using tar, I hope this quick tutorial can be useful to you. If you have any suggestion or you have any compression method, you can leave the comment below. Thank You !

Leave a Reply

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