Home » Linux Command » Most Popular Tools to Archive Files and Directories in Linux

Most Popular Tools to Archive Files and Directories in Linux

Last updated Sep 2, 2021

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.

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 logs.zip /var/log/*.log

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

Create an archive of a directory using zip

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

# zip -r logs.zip /var/log

Extract zip archive

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

# unzip logs.zip

Tool 2 – tar

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

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.

Option:

-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

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

15 Practical examples of echo command

15 Practical examples of echo command

If you are writing a bash script, you know echo command very well. It is use to display text lines on an output screen or a file. The echo command is the most common command used by all Linux users, and it is built-in Linux command. echo command syntax: echo...

0 Comments

0 Comments

Submit a Comment

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

12 + eighteen =

Follow Us

Our Communities

More on Linux Command

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!