EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux Untar

By Alokananda GhoshalAlokananda Ghoshal

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux Untar

Linux Untar

Definition of Linux Untar

Untar is defined as a command which enables users to extract files that are compressed with tar, tar.gz, tar.bz2 formats of compression. This command is used for 2 specific utilities in file operations. It first helps the user to extract or in other words unpack files in the compressed mode and once the unpacking or extraction is done, the command helps the user to uncompress the same. Listing content, extraction of a single file, or directory are some of widely used utilities of the command untar. In this article, we will go through all the utilities of the command and take deep dive using some examples to understand them in even greater detail!

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In Linux, there are lesser options available for untar in comparison to other extensively used commands, and we will discuss about all of those in detail here in this section and later in the article take a dig at the working of untar command in Linux.

1. Extraction of tar file

 Syntax:

tar -xvf <tar file name with .tar extension>

2. Extraction of tar.gz file

Syntax:

tar - xvzf <tar file name with .tar.gz extension>

3. Extraction of tar.bz2 file

Syntax:

tar -xvjf <tar file name with .tar.bz2 extension>

4. Untar tar archive File at desired location

Syntax:

tar -xvf <full location of tar file> -C <location to specified directory>

5. List Content of tar Archive File

Syntax:

tar -tvf <full location of tar file>

6. List Content of tar.gz Archive File

Syntax:

tar -ztvf <full location of tar file>

7. List Content of tar.bz2 Archive File

Syntax:

tar -jtvf <full location of tar file>

8. Extract single file from tar Archive File

Syntax:

tar -xvf <full location of tar file> <file name to be extracted>

9. Extract all files from tar Archive File matching a particular file regex

Syntax:

tar -xvf <full location of tar file> --wildcards ‘<file type>’

How Untar Command works in Linux?

In recent times most of our files that are downloaded from internet are compressed using a particular compression format and that is where a few of the formats are, tar, tar.gz, tar.bz2. The history behind, tar is; in early times tar file format was used for creation of archives to store files on magnetic tape, and hence the full form of tar is Tape ARchive. Untar is a process of reversion of the process which leads to formation of the tar file.

In the computation world, there are two different versions of tar, namely BSD tar and GNU tar. By default, most of the Linux are pre-installed with GNU tar. Another similar process of untar is gzip utility with the command gunzip. Now, talking about the different options of utility of untar they are the following 4 options:

x – provides option to the tar command to extract files from the given tar file.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,008 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

v – commands the tar to list out the files as they get extracted.

z – commands the tar command to decompress, without which by default the tar command will compress instead of decompressing.

f – helps to specify the filename which needs to be worked on for the untar process.

In the above few options, we look at all those utilities which are widely used. Apart from this, we also have other utilities like:

  • wildcard option: This option allows the user to search for a type of file extraction. For example, one would like to untar only the .jpeg extension in a tar file which also contains other file types. Using the –wildcards ‘<file type>’ will allow the user to just extract the specified file type.
  • C option: This option helps in untarring the specified files to a particular path location; incase one needs this utility specifically.
  • Delete option: Though not a part of untar option, but a utility closely associated with untar is removal of a file from a tar archive. Using the –delete option assists the user to delete a specific file in a tar archive.

With all the utilities mentioned above, this command becomes an inadvertent skill set any Linux developer possesses.

Examples

Let us discuss examples of Linux Untar.

Example #1

Extraction of tar file

Syntax:

tar -xvf eduCBA-demo.tar

Output

Linux Untar 1

Here we see that at first there are no such files present while we have the directory, but as we untar the file, all the file contents get extracted and uncompressed to the location where we are running the command from. Similar explanation goes for the below 2 examples as well (for tar.gz and tar.bz2).

Example #2

Extraction of tar.gz file

Syntax:

tar - xvzf eduCBA-demo.tar.gz

Output:

 Linux Untar 2

Example #3

Extraction of tar.bz2 file

Syntax:

tar -xvjf eduCBA-demo.tar.bz2

Output:

Linux Untar 3

Example #4

Untar tar archive File at desired location

Syntax:

tar -xvf eduCBA-demo.tar -C desiredLoc

Output:

Linux Untar 4

Here we see that the location desiredLoc has no files under it, and as we extract the file, all the file contents get extracted to the location specified i.e. desiredLoc.

Example #5

List Content of tar Archive File

Syntax:

tar -tvf eduCBA-demo.tar

Output:

Linux Untar 5

Example #6

List Content of tar.gz Archive File

Syntax:

tar -ztvf eduCBA-demo.tar.gz

Output:

linux untar 6

Example #7

List Content of tar.bz2 Archive File

Syntax:

tar -jtvf eduCBA-demo.tar.bz2

Output:

 linux untar 7

Example #8

Extract single file from tar Archive File

Syntax:

tar -xvf eduCBA-demo.tar file1.txt

Output:

example 8 

Example #9

Extract all files from tar Archive File matching a particular file regex

Syntax:

tar -xvf eduCBA-demo.tar --wildcards ‘*.txt’

Output:

In this example, we see that only the files which had “txt” as an extension gets untarred in the location!

example 9

Conclusion

With the set of examples and explanation of way of working for untar command, the usage and utilizes are even more clear for the readers and now we leave it up to you to experiment more with the different permutation combination possible with the options present in the command utility. Though not mandatory, advisable to use untar command for any of the uncompressing process of a tar, tar.gz, tar.bz2 file types as these will always have the latest options available at its disposal.

Recommended Articles

This is a guide to Linux Untar. Here we also discuss the definition, syntax, parameters, and How Untar Command works in Linux with examples. You may also have a look at the following articles to learn more –

  1. Linux Ping
  2. Vim Command in Linux
  3. Linux nslookup
  4. Linux Diff Command

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More