Linux tar Command: Everything You Need To Know

Linux tar command

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Almost every task you do in Linux involves managing files and directories efficiently. Whether it is backing up important data, transferring large directories, or compressing files to save space, the Linux tar command-line utility is an important command that solves those tasks effortlessly.

The tar command, an acronym for Tape Archive, is often used to combine multiple files and directories into a single file. It is commonly used for:

  • Backups of files that matter
  • Efficient filesystem pack and unpack
  • Sending multiple files in a single archive
  • Fast and straightforward extraction of files from an archive

There are many forms of the tar command in Linux, including tar. gz (compressed archive) or tar—xvzf (extracting a compressed archive). A systematic understanding of these varieties helps to create an effective device for system administration, data management, and to take backups.

So, let us step into the stream of Linux file archiving and master the tar command!

The Basics of the Linux tar Command

We use the tar command to create an archive file which combines many different files into a single file. Tar by itself does not compress files; it simply archives them together, unlike zip files. However, when used in conjunction with compression tools like gzip, you can create compressed archives (e.g. tar.gz. gz).

Basic Syntax of tar Command

Basic syntax of tar command is:

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

tar [options] [archive-file] [file/directory]

Where:

[options] – Indicates actions such as creating or extracting an archive

[archive-file] = The name of the output archive

[file/directory] – the files or directories to be archived

Common tar Commands and Usage

Creating a tar Archive

To make tar archive from a directory:

tar -cvf backup. tar /home/user/documents

-c (create) – Generate a new archive

-v (verbose) — Quite simply shows what is happening

-f (file) - Specifies the output file

Output:

documents/ documents/file1. txt documents/file2. txt

Creating a Compressed tar. gz Archive

To make a gzip compressed archive:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

tar -cvzf backup. tar. gz /home/user/documents

-z (gzip) – Gzipa arxivi siqadiøj

-v (verbose) – Shows the progress as it’s being written

-f this is for file to specify archive file

Output:

documents/ documents/file1. txt documents/file2. txt

Compared to an uncompressed file, this reduces file size considerably. tar file.

Extracting Files with tar -xvzf Command in Linux

To extract a tar archive:

tar -xvf backup.tar

-x (extract) – Used to extract files

-r (recursive) – Also unpack subarchives (-r => extract first n subarchives) ✔ -v (verbose) – Shows progress of extraction

-f (file) – Designates the archive

To extract a tar. gz compressed archive, use the Linux tar.gz command:

tar -xvzf backup.tar.gz

-z (gzip) – Unzip the compressed. tar. gz files

Output:

documents/ documents/file1. txt documents/file2. txt

List the contents of a tar archive

The fig command can be used to see what is inside an archive before extracting it:

tar -tvf backup.tar

-t (list) – List the contents of the archive

Output:

-rw-r--r-- user/user 1048576 Mar 10 2025 12:00 documents/file1 txt -rw-r--r-- user/user 524288 2025-03-10 12:00 documents/file2. txt

Extracting a Single File from a tar Archive

To extract a single file from an archive:

tar -xvf backup. tar documents/file1. txt

Output:

documents/file1.txt

Advanced tar Command Usage

Omitting Files from an Archive

To exclude a certain file or directory while archiving:

tar --exclude="*.log" -cvzf backup.tar.gz /home/user/documents

This will exclude all. log files from the archive.

Splitting Large Archives

To split an archive into several smaller ones (for instance, for large files):

tar -cvzf - backup. tar. gz | split -b 500M - backup_part_

This creates 500MB chunks of the archive.

CyberPanel — File Management

CyberPanel

CyberPanel, a web hosting control panel, makes file and storage management in Linux servers easy.

  • Backup and Restore Management – CyberPanel gives you a straightforward method to create and restore backups, employing tar as the compression method.
  • Easy File Management – Using CyberPanel’s File Manager, users can upload, download, and extract tar files in a browser.
  • Database Backups – CyberPanel automatically backs up MySQL/MariaDB using tar compression for less storage.
  • Log Management – Helps manage log files and avoids excessive storage usage through automated cleanup.

Users using CyberPanel do not ever have to manually run complex commands again; file compression, backups, and extractions are simple.

FAQs on tar Linux Command

1. What is the purpose of the Linux tar command?

Linux comes with the tar command for packing many files into one file. It assists with efficiently organizing, transferring, and backing up data.

2. How does tar differ from zip?

The tar command archives a bunch of files into one but does not compress them by default, while zip does both archive and compress files. Tar is often used in conjunction with gzip to produce. tar. gz compressed archives.

3. Can the Linux tar command preserve file permissions and ownership?

Yes, the tar command preserves file permissions and ownership when creating and extracting archives, which makes it useful for backing up and migrating a system.

4. Is tar available by default in all Linux distributions?

tar is a command-line utility that is even there as a built-in in practically all distributions of Linux because it is used for packaging and backup.

Final Thoughts: Become a Linux tar Command Expert!

We have learned how to use the Linux Tar Command to Archive, Compress, and Back Up Files. Whether you are in charge of System Backups, migrating large files, or optimizing storage, tar will make your Linux workflow efficient.

Ready to make managing files a bit easier? So, try CyberPanel for automatic backups and storage management!

Hasib Iftikhar
I'm Hasib Iftikhar, a dedicated technical writer at CyberPanel, joining the team in July 2024. With three years of extensive experience in content writing, I specialize in copywriting, article writing, guest posting, affiliate content writing, and SEO. My expertise ensures that each piece of content I create is engaging, informative, and optimized for search engines, helping businesses enhance their online presence and reach their target audience effectively.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!