This guide intends to teach you How To Create or Make a Tar.Gz File in Linux.
Tar is a powerful archiver that is frequently used for collecting files and archiving them. It was created to produce archives for data storage on tapes, thus the name “Tape Archive”. It was initially included in UNIX version 7 in 1979, and it is currently accessible on a variety of systems.
Steps To Create Tar.Gz File in Linux
To complete this guide, you must log in to your Linux server as a root or non-root user with sudo privileges and follow the steps below.
The general syntax of making a tar file is shown below:
tar -czf archive-name.tar.gz file-name…
tarto create a new archive.
-z– sets the compression method to gzip.
-f archive-name.tar.gz– specifies the archive name.
file-name...a space-separated list of files and directories to be added to the archive.
Make a tar.gz file in Linux
At this point, you can follow the steps below to create your tar.gz file.
For example, to create an archive named “archive.tar.gz” from “file1” and “file2” you would use the following command:
tar -czf archive.tar.gz file1 file2
On success, the command doesn’t print any output. To verify that the archive is created, list the directory contents with
If you want to create the tar.gz in a specific directory, provide a full path to the archive file:
tar -czf /home/user/archive.tar.gz file1 file2
Also, you can create tar.gz files from the contents of one or more directories or files. By default, directories are archived recursively unless
--no-recursion option is specified.
The following example shows how to create an archive named “web_backup.tar.gz” of the
tar -czf web_backup.tar.gz /var/www/website
If you are running a system that has an older version of tar that doesn’t support compression, you can use the
tar -czf - file1 file2 | gzip > archive.tar.gz
In the example above, the
tar command outputs the archive to stdout (represented by
-). The archive is piped to
gzip, which compresses and writes the archive to the disk.
These are the basic uses of making a tar file in Linux.
At this point, you have learned to Create a tar.gz file in Linux.
Hope you enjoy it.
Also, you may be like these articles: