Thursday, January 21, 2021

Most Popular Tools to Archive Files and Directories in Linux

Must read

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.
- Advertisement -

File archive is more important for any system administrator.

There are numbers of archive tools used in Linux to archive files for storing with minimum space and for backup of data.

- Advertisement -

Today, In this article, we will check the three most essential and useful tools to archive files and directories in Linux.

Tool 1 – zip

The zip tool to use compress and decompress the file with file extension “.zip,” it is essential an useful for all system administrator to do day-to-day work.

Create an archive of files using zip

To create an archive of any file use zip command and desired archive file name with “.zip” extension and file name which need to archive, as shown below:

# zip /var/log/*.log

In the above example make a archive file for all file under /var/log directory whose having “.log” extension.

Create an archive of a directory using zip

- Advertisement -

Similarly, the above example, we can use zip to archive directory also by using the “-r” option, as shown below:

# zip -r /var/log

Extract zip archive

You can use unzip command to extract the archived file with “.zip” extension, as shown below:

# unzip

Tool 2 – tar

The tar is another most essential archive tools for system administrators and Linux lovers.

- Advertisement -

Most of the time, we use the tar archive to keep backup of data.

Create an archive of files using tar

To create archive files using the tar command-line tool you should use “-c” and “-f” option with tar, as shown below:

# tar -cf logs.tar /var/log/*.log

In the above example, we created logs.tar archive file for all file under the directory “/var/log” whose having “.log” extension.


-c = use to create an archive file
-f = use to run the command forcibly

Create Archive of directory using tar

To create an archive file for an entire directory using tar command, as shown below:

# zip -cf logs.tar /var/log

Extract tar archive file

To extract the tar archive file use tar command with the “-x” option, as shown below:

# tar -xf logs.tar

The option “-x” use to extract the archived file.

Tool 3 – gzip

Gzip is also one of the important tools for the archive. It also supports to take input of data as standard input or through pip and create an archive file.

Create an archive of files using gzip

You can create an archive file using gzip command, as shown below:

# gzip -k apache_access.log

Create an archive file of piped data

You can also create an archive file for piped data by using the following command:

# cat /var/log/messages | gzip > messages.gz

Extract “.gz” archive file

You can use the following command to extract “.gz” archive file:

# gunzip apache_access.log.gz

Tar + Gzip tool

The most useful archive tool when you use tar with gzip.

To use both in the single command, you can use tar command with the “-z” option.

Create an archive of files

# tar -czf logs.tar.gz /var/log/*.log

Create an archive of a directory

# zip -czf logs.tar.gz /var/log

Extract an archive file

# tar -xzf logs.tar.gz
- Advertisement -
- Advertisement -

More articles


Please enter your comment!
Please enter your name here

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Latest article