Open In App

untar Command in Linux

Last Updated : 27 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The tar command is one of the most essential tools in Linux for compressing and extracting files. While there isn't an actual untar command, this is common term in the Linux world, referring to the process of extracting files and directories from a tar archive. If you’ve ever downloaded software or backups in compressed formats than you know that how to extract them efficiently is crucial.

This article will explain the range of operations, from the most basic to the advanced, that can be applied to tar archives in Linux.

What is the untar Command in Linux?

As mentioned, untar is not a command in its own right in Linux, but rather describes the usage of the tar command to extract files from an archive. Tar is referred to as tape archive and is a single command that will consolidate merging all the selected files and folders into one single folder while preserving the file structure and attributes of each document, image or file in the archive.

Syntax:

 tar -xvf archive.tar
  • -x: It extract files from the archive
  • -v: It is used for verbose mode which shows the extraction process
  • -f: It specifies the archive file

How to Use the Untar Command

1. Extract a .tar File

This takes out all the files and puts them into the current folder.

tar -xvf filename.tar

2. Extract a .tar.gz (Gzipped Tarball) File

The -z flag is added to process files that are compressed with gzip.

 tar -xzvf filename.tar.gz

3. Extract a .tar.bz2 (Bzip2 Compressed) File

The -j flag is added to process files compressed with bzip2.

 tar -xjvf filename.tar.bz2

4. Extract to a Specific Directory

Using the command below, the extraction can be redirected to a different folder using option -C.

 tar -xvf filename.tar -C /path/to/directory

5. Extract Specific Files from an Archive

Only file1.txt and file2.txt will be extracted from the archive.

 tar -xvf filename.tar file1.txt file2.txt

6. List Contents of a Tar File Without Extracting

This retrieves the contents of the archive without extracting it.

 tar -tvf filename.tar

Advanced Tar Options

Linux has the tar command that provides multiple advanced options for improving file archiving and extraction processes. With these options, users can extract individual files, manage compressed archives, and guide extractions into designated directories with ease. Learning these options is important to manage.tar,.tar.gz, and.tar.bz2 files properly.

OptionDescription
-xExtract files from the archive
-vDisplay extraction details
-fSpecify archive filename
-zHandle gzip-compressed archives
-jHandle bzip2-compressed archives
-CExtract to a specified directory
-tList files inside an archive
--wildcardsExtract files using patterns

Troubleshooting Common Issues

While extracting files with the tar command on Linux using the command line could give the user a tough time, here are some common errors and ways to fix them.

1. "Permission Denied" Error

If you do not have the requisite permission to extract a file, then to execute the command try using the sudo option alongside the command. use the below command:

sudo tar -xvf filename.tar

2. "No such file or directory" Error

The problem arises as soon as the designated archive file could not be tracked down in the current working directory. Use the below command:

ls -l filename.tar

3. "Archive File Corrupted" Error

Before trying to extract files from an archive, always check to see if the archive is damaged. When damaged, try to do the following:

tar -tvf filename.tar

Conclusion

With this, it is certain that the tar command enables you to manage compressed files on Linux with much ease. Utilizing these commands would make you familiar with the untar command, and in turn help system administrators and users manage their files with more ease. Practice these commands to enhance your Linux expertise and streamline your workflow.


Next Article
Article Tags :

Similar Reads