tar Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The tar command is one of the most widely used commands in Linux. It is used to create, view, and extract files from archives. The tar command is a powerful tool that can be used to manage large amounts of data efficiently. In this article, we will discuss the syntax, options, and usage of the tar command in Linux.

Linux tar Command Syntax

The syntax for the tar command is as follows:

Where:

  • Options: Used to specify various actions to be taken by tar command.
  • File/directory: Specifies the name of the archive file to be created or the directory to be archived.

tar Command Options:

  • -c: Create a new archive.
  • -x: Extract files from an archive.
  • -t: List the contents of an archive.
  • -f: Use the following archive file.
  • -v: Verbose output.
  • -z: Compress or decompress the archive using gzip.
  • -j: Compress or decompress the archive using bzip2.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Example Usages

  • Create a new archive:

    Explanation: This command will create a new archive named 'archive.tar' and add the files 'file1.txt' and 'file2.txt' to it.

  • Extract files from an archive:

    Explanation: This command will extract all the files from the archive 'archive.tar' to the current directory.

  • List the contents of an archive:

    Explanation: This command will list the contents of the archive 'archive.tar'.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Tips

  • You can add multiple files to an archive by separating their names with a space.

  • You can use the wildcard character '*' to add all files in a directory to an archive.

Advanced Use Cases of tar Command in Linux

  • Compress an archive using gzip:

    Explanation: This command will create a compressed archive named 'archive.tar.gz' and add the files 'file1.txt' and 'file2.txt' to it using gzip compression.

  • Compress an archive using bzip2:

    Explanation: This command will create a compressed archive named 'archive.tar.bz2' and add the files 'file1.txt' and 'file2.txt' to it using bzip2 compression.

  • Extract files from a compressed archive:

    Explanation: This command will extract all the files from the compressed archive 'archive.tar.gz' to the current directory using gzip decompression.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The tar command is a powerful tool for managing archives in Linux.

  • You can use it to create, view, and extract archives.

  • It supports a wide range of options for customizing the archive creation and extraction process.

  • You can also use it to compress and decompress archives using gzip or bzip2 compression.

eam