You can also select the files and directories you want to extract and the destination directory where you want to extract them. You can also extract only specific files or directories from a tar.gz archive, by providing their names after the archive name. You need to use the exact names and paths as listed by the tar -t command. The GNU tar command included with Linux distributions has integrated compression.
How to Create a tar.gz File in Linux
Most of the time, you will get your hands on a compressed package that needs extracting. Again, the above command extracts to the current working directory by default. You can use the -C option to extract to a different directory (in this case, /home/user/files). Of course, that’s not to say .tar files are some kind of “lesser” format than .zip.
You’ll want to replace “tarfile” with the path to the tar.gz file that you’re trying to extract. For a more detailed explanation on how the tar command works, be sure to read our guide to compressing and extracting files in the Linux Terminal. The tar command is extremely powerful, and you can do things like list or search for files in a tar archive, or extract a single file. And now you can use the 7-Zip File Manager to open, view, or extract files from tar.gz and other archives. If you want a specific file, you can drill down into the folder, or you can simply click the “Extract” button and choose a location to put all the files. 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.
What’s the difference between .tar and .tar.gz files?
For TAR.GZ files, you will have to unzip the compressed archive to TAR, and then further extract the TAR file using 7-Zip. The first part of the command writes the archive.tar file to the standard output. The second command reads the archive.tar file from the standard input and compresses it accordingly.
Extract just one file or directory
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. A “.tar” file is a collection of files compressed into a single file or archive. Short for “Tape ARchive,” the name “TAR” is a throwback to when files were stored on magnetic tape drives. If you want to create your own tar.gz file, you can use the tar command with the -c option, which tells tar to create a new archive. You also need to use the -z option to compress the archive with gzip, and the -f option to specify the file name.
- It’s often useful to list the contents of a .tar.gz file without having to unzip the entire archive.
- Creating archives is an important step when you’re backing up your Linux file system.
- Note that this command also works with other common compression formats such as .tar.bz2.
- Like the tar utility, gzip also allows you to zip and unzip multiple files or entire directories at a time.
- To do that, you can use the tar command with the -t option, which lists the contents of an archive without extracting it.
You can easily extract .tar.gz files using third-party tools like 7 zip and Winrar on the Windows system. You can notice in the above image that the archive files are extracted in the same working directory. But it does not compress the data, which results in a larger file size compared to compressed formats. If you’re familiar with packages in Linux, you may have come across a TAR or a TAR.GZ file. While experienced users know what is a TAR file and how to extract it, Linux newbies might face some difficulties in figuring out what to do with it. You can easily unzip the resulting .tar.gz file with the decompress (-d) option.
Gzip is also more common, with some stripped-down Linux systems including gzip support by default, but not bzip2 support. In general, though, gzip and bzip2 are practically the same thing, and both will work similarly. 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. The aforementioned command will extract the archive.tar.gz file to the /Downloads folder. But with .zip being the easier of the two to use, why use .tar in the first place?
Simply add a space-separated list of the files you want to extract. This command extracts (-x) the file (-f) specified (in this case, filename.tar.gz) to the current directory. Note that this command also works with other common compression formats such as .tar.bz2.
To access the Windows command line, search for “command prompt” or “cmd” in the search bar. Right-click the first result and select the “Run as administrator” option. Once you’re comfortable why itʼs important you know how to keep track of petty cash with the basics, it’s useful to explore other features.
However, there are also many third-party tools you can install for a more user-friendly experience. 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. On Windows, the easiest way to handle .tar files is to install the LGPL open source 7-Zip utility. Its name implies it’s a zip utility, but it also works with tar archives, and even provides commands for the cmd command-line interface. Most file managers, such as Nautilus, Dolphin, or Thunar, support extracting tar.gz files by right-clicking on the file and choosing the Extract option from the context menu.
After reading this article, you know how to extract or unzip .tar.gz file in Linux using different methods and tools. A user-friendly way to extract files from a .tar.gz archive is via a Graphical User Interface (GUI). In this guide, you will learn how to extract or unzip .tar.gz files in Linux. It’s easy to get confused when navigating between .tar, .tar.gz, and .gz – not to mention zipping and unzipping them. Here are a few frequently asked questions we commonly hear from users working with .tar.gz files. This error occurs if you try to decompress a file without specifying a decompression utility, specifically -z for gzip.
As a result, it has become a common file extension for many open-source software packages and other resources. To extract a tar.gz file using the tar command, you need to use the -x option, which tells tar to extract the files from the archive. You also need to use the -z option to indicate that the archive is compressed with gzip, and the -f option to specify the file name. There are several ways to extract or unzip a tar.gz file in Linux, depending on the tool you have available or prefer to use.
Extracting .tar.gz Files for Windows
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. That means users can download and use it for free during a trial period.
This is good and pretty comprehensive, Seth.One thing to point out is that, since .jpg and .png files are already compressed, you won’t get much compression with gzip. The command includes a large number of additional options, so we can’t possibly list them all here. Run the info tar command at the shell to view the tar command’s detailed information page. Gzip is faster, but it generally compresses a bit less, so you get a somewhat larger file. Bzip2 is slower, but it compresses a bit more, so you get a somewhat smaller file.
Thankfully, unless you’re somehow missing your tar or gzip utility, most common errors are very easy to fix. It’s often useful to list the contents of a .tar.gz file without having to unzip the entire archive. Technical details aside, all you need to remember is that .zip files are more accessible but less space-efficient, while .tar files are less accessible but more space-efficient. As a result, one isn’t necessarily better than the other — it’s all a matter of application. Some of the most popular archive managers for Linux are File Roller, Ark, Xarchiver, and PeaZip.