Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash tar - 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


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.