Tar command Linux examples
# Introduction to Tar Command
Tar is one of the widely used archiving tools in Linux. It is used to archive and compress multiple files and directories into one file. Tar is also known as Tape Archive, which is used to store and extract files from a single source. It is useful in reducing the size of the file, making it easier to store and share.
The tar command is used to create and manipulate tar archives. It is an effective way to store and share multiple files in a compressed format. It can also be used to back up files, as it provides a complete backup of an entire directory structure.
The tar command can be used to create archives in different formats such as GNU Tar, BSD Tar, PAX, etc. It also provides advanced options such as compression, encryption, incremental backup, etc. In this article, we will discuss the basic syntax and usage of the tar command with some examples.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar
The tar command is a Linux utility used to archive, compress, and extract files. It is used to create and manipulate tar archives, which are collections of files that are compressed and stored in a single file.
Example 1: Create a Tarball
This example will create a tarball containing all files in the current directory.
`tar -cvf archive.tar ./*`
Example 2: Extract a Tarball
This example will extract the contents of a tarball named archive.tar into the current directory.
`tar -xvf archive.tar`
Example 3: Create a Tarball with Compression
This example will create a tarball named archive.tar.gz containing all files in the current directory, using gzip compression.
`tar -zcvf archive.tar.gz ./*`
Example 4: Extract a Tarball with Compression
This example will extract the contents of a tarball named archive.tar.gz, using gzip compression.
`tar -zxvf archive.tar.gz`