Learn How to Tar a Folder in Linux Like a Pro!


In the world of Linux, tar is an essential command-line tool that enables users to create compressed archives of files and directories. Whether you’re looking to back up your data, transfer files, or simply save disk space, knowing how to tar a folder is a valuable skill. In this article, we’ll walk you through the process of creating and extracting tar archives, provide insights into advanced options, and address common FAQs to ensure you’re well-equipped with the knowledge you need.

How do I Tar a Folder in Linux?

To tar a folder in Linux, follow these steps:

  1. Open the Terminal: Launch the terminal application on your Linux system. You can usually find it in the Applications or System Tools menu.
  2. Navigate to the Folder: Use the cd command to navigate to the directory containing the folder you want to tar. For example, if your folder is located in the Documents directory, you would use the command: cd Documents
  3. Tar Command: Once you’re in the desired directory, use the following command to create a tar archive of the folder:bashCopy codetar -cvf archive_name.tar folder_name Replace archive_name.tar with the desired name for your archive file and folder_name with the name of the folder you want to tar.
  4. Compression (Optional): If you want to compress the archive using gzip, you can add the z option to the command:bashCopy codetar -czvf archive_name.tar.gz folder_name This will create a compressed tar archive.
  5. View Archive Contents: To view the contents of the created tar archive, use the following command:bashCopy codetar -tvf archive_name.tar This will display a list of files and directories within the archive.
  6. Extracting the Archive: To extract the contents of the tar archive, use the following command:bashCopy codetar -xvf archive_name.tar If the archive is compressed, use:bashCopy codetar -xzvf archive_name.tar.gz The extracted files will appear in the current directory.

Understanding Tar Options

The tar command comes with various options that enhance its functionality. Some commonly used options include:

  • -c: Create a new archive.
  • -v: Verbosely display the progress of the operation.
  • -f: Specify the archive file’s name.
  • -z: Compress the archive using gzip.
  • -x: Extract files from an archive.

Advanced Tar Techniques

Including Specific Files

To include only specific files in the tar archive, list their names at the end of the tar command. For instance:

tar -cvf archive_name.tar file1.txt file2.jpg

Excluding Files

To exclude certain files from the archive, use the --exclude option:

tar -cvf archive_name.tar --exclude=unwanted_file.txt folder_name

Frequently Asked Questions (FAQs)

Can I tar multiple folders at once?

Absolutely! You can list multiple folder names after the tar command to archive them together.

How do I extract the archive in a specific directory?

Use the -C option followed by the directory path where you want the contents to be extracted.

Is there a way to see the progress while extracting files?

Yes, adding the -v option during extraction will display the progress.

Can I password protect my tar archive?

While tar itself doesn’t provide password protection, you can combine it with other tools like gpg to achieve encryption.

Are there graphical interfaces for creating tar archives?

Yes, many Linux file managers offer a built-in option to create tar archives via their graphical interfaces.

Can I use tar to compress system backups?

Certainly! Tar is commonly used for creating backup archives of entire system configurations.

How to create a tar file?

To create a tar file, use the command tar -cvf filename.tar files_or_directories.

How to tar a directory in Linux?

To tar a directory in Linux, run tar -cvf output.tar /path/to/directory.

How to make a tar file in Linux?

To make a tar file in Linux, execute tar -cvf output.tar files_or_directories.

How do I tar a folder in Linux?

To tar a folder in Linux, open the terminal and type tar -cvf output.tar /path/to/folder.

How to tar a file on Linux?

To tar a file on Linux, use the command tar -cvf output.tar filename.


In the world of Linux, knowing how to tar a folder is an indispensable skill. With the simple yet powerful tar command, you can efficiently create compressed archives, store files, and share data. By following the steps outlined in this guide, you’re well on your way to becoming a Linux archiving expert. So go ahead, try it out, and unlock the potential of this versatile command.

Leave a comment