bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Bash/File Compression
Bash•File Compression

Bash tar Command - An archiving utility

Using the tar Command

The tar command is used to create, maintain, modify, and extract files from an archive file.

TAR Options Overview

Here are some common options you can use with the tar command:

  • -c - Create a new archive
  • -x - Extract files from an archive
  • -t - List the contents of an archive
  • -z - Filter the archive through gzip
  • -v - Verbosely list files processed
  • -f - Specify the filename of the archive

Option: -c (Create)

The -c option creates a new archive with the specified files.

Example: Create Archive

tar -cvf archive.tar file1 file2
file1
file2

Option: -x (Extract)

The -x option extracts files from an archive.

Example: Extract Files

tar -xvf archive.tar
file1
file2

Option: -t (List)

The -t option lists the contents of an archive without extracting them.

Example: List Archive Contents

tar -tvf archive.tar
-rw-r--r-- user/user 1234 2025-04-10 12:00 file1
-rw-r--r-- user/user 5678 2025-04-10 12:00 file2

Option: -z (Gzip)

The -z option filters the archive through gzip, compressing or decompressing it.

Example: Gzip Compression

tar -czvf archive.tar.gz file1 file2
file1
file2

Option: -f (File)

The -f option specifies the filename of the archive to create or operate on. It should be used as the last option before the archive name.

Example: Specify Archive Filename

tar -cvf archive.tar file1 file2
file1
file2

Option: -v (Verbose)

The -v option provides verbose output, listing files as they are processed.

Example: Verbose Output

tar -xvf archive.tar
file1
file2

Previous

Bash unzip Command - Extract from ZIP archive

Next chapter

File Permissions

Start with Bash File Permissions and Ownership

This chapter

Overview
3

Lessons

6m

Read time

1. Bash zip Command - Package and compress (archive) files2. Bash unzip Command - Extract from ZIP archive3. Bash tar Command - An archiving utility

On this page

Using the tar CommandTAR Options OverviewOption: -c (Create)Example: Create ArchiveOption: -x (Extract)Example: Extract FilesOption: -t (List)Example: List Archive ContentsOption: -z (Gzip)Example: Gzip CompressionOption: -f (File)Example: Specify Archive FilenameOption: -v (Verbose)Example: Verbose Output