Compressing files and directories is one of the most basic functionalities of an operating system. On Linux, the standard format for creating a compressed file is Tape Archive or tarball, or simply TAR.
You can also apply further compression using gzip and bzip2 to create TAR.GZ and TAR.BZ2 files, respectively. tar alone is a raw archiving utility for Linux-based systems.
Before we look at how to make a TAR directory, let's make sure you have tar installed on your Linux system.
Installing tar on Your Linux Desktop
Most of the modern Linux distros have tar installed by default. However, if you don't have it, you can install it using the following commands:
On Debian and Ubuntu-based distros:
sudo apt install tarOn Arch Linux and other Arch-based distros:
sudo pacman -S tarOn RHEL, CentOS, and Fedora:
sudo yum install tarMaking a TAR Directory and Compressing Data on Linux
The first most crucial step is to open the Terminal in the directory where your files or subdirectories are present. You can do so by either using the cd command or right-clicking in the directory and selecting Open in Terminal from the context menu.
Now, to compress files or directories using tar, you can simply use the following commands.
To create a TAR directory:
tar -cvf archivename.tar directory_pathTo compress a directory and create a TAR.GZ file:
tar -czvf archivename.tar.gz directory_pathIn the above commands, c, z, v, and f stand for Create, gzip, Verbose, and Filename, respectively. You can learn about the difference between TAR and TAR.GZ here.
For example, to compress a folder named Test using tar:
tar -czvf Test-file.tar.gz Test We created a TAR file named Test-File using the tar command in the example above.
Create a TAR Directory Using 7-Zip
If you don't prefer command-line solutions, you can also install 7-Zip. Once installed, simply right-click on the directory and click Compress. It lets you choose the TAR.XZ format, where XZ is a type of compression like gzip.
Compress Your Data on Linux Using TAR Directories
So now you know different ways to make TAR directories on Linux. You can use these methods to compress your data for various purposes like sharing or saving.
You can't open or launch TAR files or directories as you'd with normal files and folders. You need to decompress the tarball first to access its contents.