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.
Option | Description |
---|
-x | Extract files from the archive |
-v | Display extraction details |
-f | Specify archive filename |
-z | Handle gzip-compressed archives |
-j | Handle bzip2-compressed archives |
-C | Extract to a specified directory |
-t | List files inside an archive |
--wildcards | Extract 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.
Similar Reads
Unzip Command in Linux
As an open-source operating system, Linux presents plenty of powerful and versatile instructions for dealing with files and directories. One such command that performs an important role in coping with compressed files is the "unzip" command. Compressed files are a common way to keep space and share
8 min read
RPM Command in Linux
The RPM (Red Hat Package Manager) command is a fundamental tool in the world of Linux package management. It is widely used in Red Hat-based distributions like Fedora and CentOS, as well as other RPM-based distributions. The RPM command allows users to install, query, verify, and manage software pac
6 min read
ls Command in Linux
The ls command is one of the most used commands in the Linux terminal to display the files and directories or path in the terminal. So, using the ls command is a basic skill for navigating the Linux file system, handling files, and managing directories. What is the ls Command in LinuxThe ls command
10 min read
Swapon Command in Linux
The Linux swapon command serves the purpose of activating a swap partition in Linux systems. A swap partition is essentially a dedicated space used when the system's RAM (Random Access Memory) becomes fully utilized. It temporarily holds data that can be retrieved when required, making it particular
5 min read
grep command in Unix/Linux
The grep command in Unix/Linux is a powerful tool used for searching and manipulating text patterns within files. Its name is derived from the ed (editor) command g/re/p (globally search for a regular expression and print matching lines), which reflects its core functionality. grep is widely used by
7 min read
du Command in LINUX
The du command in Linux is a powerful utility that allows users to analyze and report on disk usage within directories and files. Whether youâre trying to identify space-hogging directories, manage disk space efficiently, or simply gain insights into storage consumption, the du command provides valu
5 min read
dnf Command in Linux
Linux is a versatile operating system. It has many commands that can change the Linux working functionality of the operating system. Every Linux has a different package manager that helps us to install the software in the Linux operating system. The `dnf` command is a package manager command in Red-
4 min read
Fun Commands in Linux
Linux isn't just for coding and administrationâit can also be a lot of fun. With a variety of terminal commands, you can add some entertainment to your Linux experience. Below is a list of some cool and fun commands you can use in Linux to enhance your terminal experience. Weâll also cover how to in
4 min read
fuser command in Linux
fuser is a command line utility in Linux. fuser can identify the process using the files or sockets. This command can be also used to kill the process. In this article, we are going to see how to use the fuser command to list the processes and kill the processes associated with files and directories
4 min read
Linux Commands
Linux commands are essential for controlling and managing the system through the terminal. This terminal is similar to the command prompt in Windows. Itâs important to note that Linux/Unix commands are case-sensitive. These commands are used for tasks like file handling, process management, user adm
15+ min read