Compressing and Decompressing Files with TAR

compressing files with tar is a simple process that can be achieved using the tar command in Linux. The tar command allows you to create, extract, list, and delete archives. In this article, we will focus on compressing files.

To start, let’s navigate into the directory where we want to compress our files:


As the terminal or console is opened, type the following commands to compress a file:

tar -cvf [ARCHIVE_FILE] [FILE_TO_COMPRESS]

Here are the options used in this command:

  • c: stands for create and is used to create an archive.
  • v: stands for verbose mode, which provides detailed information about each step of the process.
  • f: stands for file, and specifies the name of the archive that we want to create.
  • [ARCHIVE_FILE]: This is the name of the archive file that we will create. The extension should be “.tar” or “.tar.gz”.
  • [FILE_TO_COMPRESS]: This is the name of the file that we want to compress.

For example, if you want to create an archive called “archive.tar” and compress a file called “example.txt”, use the following command:

tar -cvf archive.tar example.txt

This will create a new archive called “archive.tar” in the current directory, containing the “example.txt” file.


To decompress files, navigate into the same directory where the compressed file is located.

tar -xvf [ARCHIVE_FILE]

Here are the options used in this command:

  • x: stands for extract and is used to extract an archive.
  • v: stands for verbose mode, which provides detailed information about each step of the process.
  • f: stands for file, and specifies the name of the archive that we want to extract.
  • [ARCHIVE_FILE]: This is the name of the compressed file that we will decompress.

For example, if you have an archive called “archive.tar” in the current directory and you want to decompress it, use the following command:

tar -xvf archive.tar

This will extract all files from the “archive.tar” file into the same directory.


To list the contents of a compressed file, navigate into the same directory where the compressed file is located:

tar -tvf [ARCHIVE_FILE]

Here are the options used in this command:

  • t: stands for list and is used to list the contents of an archive.
  • v: stands for verbose mode, which provides detailed information about each step of the process.
  • f: stands for file, and specifies the name of the archive that we want to list.

For example, if you have an archive called “archive.tar” in the current directory and you want to list its contents, use the following command:

tar -tvf archive.tar

This will display a detailed listing of all files contained within the “archive.tar” file.