How to Untar Unzip or Extract Tar Files in Unix or Linux


how to unzip a tar file

You just need to change the option z (gzip) to j (bz2). This is why you’ll often find software available in a ‘tarball‘. Tar is one of the most common tool used for archiving files in Linux.

You can use the -C option to extract to a different directory (in this case, /home/user/files). For sending and storing, both .zip and .tar.gz files allows you to send relatively large packages as a single file. However, there are some pretty major differences when it comes to accessing data within the files and the compression efficiency. Knowing how to unzip a .tar.gz file allows users to extract and access the archives’ contents efficiently. Whether you prefer command-line tools or graphical file archivers, the extraction process is pretty simple. Now that you have seen how the different types of compression affect the overall file size, let’s look at extracting those files.

Compress Multiple Directories or Files at Once

You may also be interested in learning about the best WinZip alternatives to compress files. That means users can download and use it for free during a trial period. Also, its trial version does not have time limitations, and users can still use it even after the trial period has expired, with occasional reminders to purchase the license. These files can be used in incremental backup strategies – where only new or modified files are added to the archive.

Use the following command to compress an entire directory or a single file on Linux. It’ll also compress every other directory inside a directory you specify — in other words, it works recursively. This error occurs when trying to extract specific files or directories from a .tar.gz file using tar.

You will learn how to list the contents of a tar archive without unpacking it and how to extract only a single file or a single directory. The GNU tar command included with Linux distributions has integrated compression. It can create a .tar archive and then compress it with gzip or bzip2 compression in a single command. That’s why the resulting file is a .tar.gz file or .tar.bz2 file. The tar command can extract the resulting archives, too. Since .tar.gz compresses multiple files all at once, it can take advantage of similarities between individual files to save on space.

How to install Node.js and npm on Windows, macOS, and Linux

Generally speaking, a collection of files archived and compressed as a .tar.gz are more space-efficient (i.e., smaller) than the same collection compressed as a .zip. With the command prompt open, use the appropriate commands to change the current working directory (cd) to the location of the .tar.gz file you want to unzip. Alternatively, you can also specify a source and destination file path when using the tar utility. Like the tar utility, gzip also allows you to zip and unzip multiple files or entire directories at a time.

Extract Files to the Current Directory

The destination directory must exist so make sure to use mkdir command to create one beforehand. I recommend going through the help documentation yourself to find even more possibilities once you feel comfortable. Once you’ve done this successfully, you’ll notice that the icon for tar.gz files will change to a 7-Zip icon.

Compress an Entire Directory or a Single File

how to unzip a tar file

I have assembled some files of different types in my Documents folder. We will look at how the file size is changed by the compression through several examples. Once you have an archive, you can extract it with the tar command. The following command will extract the contents of archive.tar.gz to the current directory. You can open most .tar.gz files using the tar command built in to Linux, macOS, and Windows 10.

Looking Inside Tar Files Before Extracting Them

While slightly different, they are quite lightweight and offer a much simpler alternative to using the command line. You can also use –wildcards to extract all files with a certain extension or name. Otherwise, keep reading to learn how to cryptocurrency mining 2020 unzip .tar.gz files in Linux, macOS, and Windows. This example uses example1.tar.gz in the Home directory. The output shows a newly created archive example1.tar.gz.

As a result, one isn’t necessarily better than the other — it’s all a matter of application. In Linux, users have multiple ways to extract .tar.gz files – through the terminal and graphical file archivers. 7-Zip is a free and open-source tool with high compression ratios & supports a wide range of archive formats.

It’s important to remember that extensions are not necessary on Linux and other Unix-based systems. Your Unix system can typically identify files by their headers regardless of extension, but using the common naming scheme can help avoid confusion. You may use the file command in Linux to know the type of a file. It’s the same as the archive creation command we used above, except the -x switch replaces the -c switch. This specifies you want to extract an archive instead of create one.

  1. That means they maintain their original characteristics.
  2. Files that have a .tar.gz or a .tar.bz2 extension are compressed archive files.
  3. Let’s say you’ve downloaded two files of sheet music.
  4. If you’re not comfortable with the terminal or command line, third-party tools such as 7-Zip offer a more user-friendly alternative.

We only need to add the -z option when we’re extracting files from a .tar.gz file. Likewise, we don’t need the -j option to list the files in a tar.bz2 file. If we want to extract the files to a location other than the current directory, we can specify a target directory using the -C (specified directory) option. Files that have a .tar.gz or a .tar.bz2 extension how to buy feg are compressed archive files.

Where most operating systems make it easy to extract and create .zip files, the same can’t really be said for .tar files — at least not in ways that are easy to notice. From videos to entire software packages, many files are compressed and stored using the .tar.gz format. While extracting a .tar.gz file isn’t quite as easy as unzipping a .zip, it’s still pretty straightforward. The following tar examples cover how to untar both popular formats and extract the contents of the compressed archive to a different directory.

As we see later, different compression utilities may require different methods for extracting and unzipping files. Though we mostly focus on .tar.gz files, check out the end of the article for some quick tips on extracting .tar files in other formats. You’ll encounter them frequently while using a Linux distribution like Ubuntu or even while using the ultimate test to check if your vpn is leaking the terminal on macOS.

A few simple commands are all it takes to untar, unzip or extract tar gz files from within running Linux or Unix operating environments. Hopefully this has helped you decompress, unpack and extract those compressed tar and tar gz files you downloaded from the internet. If you are looking for additional helpful solutions, you might want to check out this right mouse click open files as root article.

In Linux, the term “untar command” isn’t a standalone command. Instead, it commonly refers to the process of extracting, unzipping, or uncompressing tar and tar.gz files from a tar archive. The actual command used for this purpose is the tar command, combined with specific extraction options or arguments, enabling you to untar files, as we will cover next.


Leave a Reply

Your email address will not be published.