Notice that we don’t need to use the -z option to list the files. 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 list the files in the Download directory we will see that another directory called Guitar Songs has been created.
The tar command also provides support for extracting only specific files or directories from a .tar.gz file. 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. 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.
Options
By convention, the name of a tar archive compressed with gzip becomes .tar.gz or .tgz. To do this we’ll use almost exactly the same command as before but with one important difference. The .bz2 extension suffix tells us it has been compressed using the bzip2 command. Instead of using the-z (gzip) option, we will use the -j (bzip2) option to unzip the bz2 file.
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. This error usually occurs when a .tar has been saved as a .gz despite having never been compressed using the gzip utility. It may sound like a silly mistake, but it’s surprisingly common in situations where users directly rename files and their extensions (such as .tar and .gz) in the process. Where commands have little (if any) room for typos or omissions, many common errors are the result of small mistakes, misspellings, or incorrect formats.
Specifying the Compression Format
As you might imagine, using a different compression utility on a .tar file how to buy emc2 will result in a different double extension. Some common examples include .tar.bz2 (bzip2), .tar.br (Brotli), and .tar.zst (zstd), among many others. The most often used algorithm for compressing tar files is Gzip.
List contents of .tar.gz file in Linux
The .gz or .bz2 extension suffix indicates that the archive has been compressed, using either the gzip or bzip2 compression algorithm. The tar command will work happily with both types of file, so it doesn’t matter which compression method was used — and it should be available everywhere you have a Bash shell. You just need to use the appropriate tar command line options. Though gzip is the most common compression utility, it’s not the only one.
Extracting .tar.gz files using the tar Command
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. Otherwise, keep reading to learn how to unzip .tar.gz files in Linux, macOS, and Windows. This example uses example1.tar.gz in the Home directory.
- 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.
- Files that have a .tar.gz or a .tar.bz2 extension are compressed archive files.
- To extract a single file, provide the path and the name of the file.
- This is because most versions of tar allow both gnu and bsd style options (simplistically, gnu requires a hyphen, bsd doesn’t).
The -C option is used to specify a different directory other than the current working directory. The name “Tar” stands for “Tape Archiver” because it was used to place data on storage tapes when tar was invented. The tar program takes one or more files and “wraps” them into a self-contained file. If you plan to distribute and store .tar.gz files on your website, Kinsta’s managed hosting services can help make the most of your space. Similar to bitcoin flash crash knocks elon musk off rich list top spot the previous error, this error occurs when an archive was saved as a .tar despite not being a .tar archive.
A file with just a .tar extension is uncompressed, but those will be very rare. The easiest way to open a tar.gz file on Windows is to install how to create a btc wallet and way to make profit from it an excellent free utility called 7-Zip, which can handle tar.gz and just about any other file format. We’ve been recommending this app for years, and it’s one of the first things that we install whenever reinstalling Windows. It’s easy to get confused when navigating between .tar, .tar.gz, and .gz – not to mention zipping and unzipping them.
As a result, it has become a common file extension for many open-source software packages and other resources. While gzip compression is most frequently used to create .tar.gz or .tgz files, tar also supports bzip2 compression. This allows you to create bzip2-compressed files, often named .tar.bz2, .tar.bz, or .tbz files. To do so, just replace the -z for gzip in the commands here with a -j for bzip2. 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.