To extract tar gz file in linux

How To Extract .tar.gz Files using Linux Command Line

In this tutorial we can learn how to extract tar.gz files using Linux Command line tools.

A .tar.gz file is nothing, but an archive. It is a file that acts as a container for other files. The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update, or list files which were already stored. An archive can contain many files, folders, and subfolders, usually in compressed form using gzip or bzip2 program on Unix operating systems. Initially, tar archives were used to store files conveniently on magnetic tape. The name “Tar” comes from this use; it stands for tape archiver. You need to use the tar command which can create and manipulate archive files in .tar.gz under Unix like operating systems. It is very useful for archiving multiple files together into a single archive file. It allows us to restore files individually. Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives). tar.gz file is actually the product of two different things. Tar basically just packages a group of files into a single file bundle, but doesn’t offer compression on it’s own. To compress tar you’ll want to add the highly effective gzip compression. In this documentation, we can discuss about how to extract the tar.gz files from the command line. For this, open a command-line terminal and then type the following commands to open and extract a .tar.gz file.

Extracting .tar.gz files

1) If your tar file is compressed using a gzip compressor, use this command to uncompress it.

x: This option tells tar to extract the files.

v: The “v” stands for “verbose.” This option will list all of the files one by one in the archive.

z: The z option is very important and tells the tar command to uncompress the file (gzip).

f: This options tells tar that you are going to give it a file name to work with.

A tarball is a group or archive of files that are bundled together using the tar command and have the .tar file extension.

How To Extract .tar.gz Files using Linux Command Line

2) To uncompress tar.gz file into a different directory, use the command below:

$ tar xvzf file.tar.gz -C /path/to/somedirectory

Where the -C argument is used to specify the path to place the file. By defaults files will be extracted into the current directory. To change the directory, we use -C option.

How To Extract .tar.gz Files using Linux Command Line

3) To extract test.doc file from the file.tar.gz tarball, use the following command:

How To Extract .tar.gz Files using Linux Command Line

4) To view a detailed table of content by listing all files in archive, you can use the following command:

Читайте также:  Кали линукс для винды

How To Extract .tar.gz Files using Linux Command Line

5) To extract the .gz file without tar, you can use the following command:

How To Extract .tar.gz Files using Linux Command Line

Extracting .tar.bz2 files

This is just about the same as the gzip decompression. The major difference is that the z option has been replaced by the j option.

If your tar file is compressed using a bZip2 compressor, use the following command to extract it.

Where ‘j’ will decompress a bzip2 file.

How To Extract .tar.gz Files using Linux Command Line

If you need any further assistance please contact our support department.

21 Responses to “How To Extract .tar.gz Files using Linux Command Line”

i have total 125 tar.gz files to unzip can you suggest a command to unzip all 125 tar.gz in a single stretch

If you want to extract all the tarballs at once, in one location, use wildcard characters in command. For example, if you want to unzip all the tarballs at once located in the current directory, execute sudo tar -xzvf *.tar.gz» . Let us know if you have more questions.

Источник

How to Extract or Unzip tar.gz Files from Linux Command Line

A tar.gz file contains several compressed files to save storage space, as well as bandwidth during the downloading process. The .tar file acts as a portable container for other files and is sometimes called a tarball. The .gz part of the extension, stands for gzip, a commonly-used compression utility.

In this guide you will learn how to extract or unzip files from tar.gz files using command-line in Linux.

tutorial on extracting files using tar.gz from command line

  • Access to a command-line/terminal window
  • The tar utility (included by default)
  • The gzip utility (included by default)

Extracting tar.gz Files in Linux

Using gzip Utility

Gzip by default, extracts the file in the current directory. In this example the file is located in the Documents directory.

Below, we have used the file named test.txt. Use the name of the file you want to compress instead.

to compress a single file with gzip enter the command in your terminal window:

After zipping the file, enter the command ls to confirm that the file has been compressed. The output confirms that the file now has a .gz extension.

confirming that the file has been compressed

To decompress a file, use the gunzip command:

Again, use the ls command to confirm the extension of the file.

example file has been unzipped

To compress all the .txt files in a particular directory, type in:

The * sign is a wildcard, which means “any number of any characters.” This command would work on any (and all) filenames with the extension .txt.

This technique can be used on other file types including gzip.txt, .jpg, and .doc.

When you run gzip on multiple files at once, the system generates a compressed copy of each file. This can clutter up a directory quickly! Fortunately, there’s another tool to manage multiple files at once.

Using tar Utility

A tar.gz file is a combination of a .tar file and a .gz file. It is an archive file with several other files inside it, which is then compressed.

You can unzip these files the same way you would unzip a regular zipped file:

output in the linux terminal when extracting a tar.gz file

The basic command is tar , followed by four options:

  • x – instructs tar to extract the files from the zipped file
  • v – means verbose, or to list out the files it’s extracting
  • z – instructs tar to decompress the files – without this, you’d have a folder full of compressed files
  • f – tells tar the filename you want it to work on
Читайте также:  Linux посмотреть размер папки

To list the contents of a .tar file before you extract it, enter:

To instruct tar to put the extracted unzipped files into a specific directory, enter:

tar –xvzf documents.tar.gz –C /home/user/destination

how to unzip a tar.gz file to a specific destination in Linux

To create a tar.gz file, use the following command:

tar –cvzf documents.tar.gz ~/Documents

Similar to the tar command, it condenses all the content located in the /home/user/Documents directory into a single file, called documents.tar.gz. The addition of the –z option is what signals tar to compress the files.

To add multiple files to a tar file, use the command:

tar -cvf documents.tar ~/Documents

This copies the contents of your Documents folder into a single file, called documents.tar. The options -cvf work as follows:

  • c – creates a new archive
  • v – verbose, meaning it lists the files it includes
  • f – specifies the name of the file

To extract the files from a .tar file, enter:

This command extracts and lists all files from the documents.tar file. The -x option tells tar to extract the files.

Command that extracts all files from a zipped document

You can also use xargs with tar to create a tar.gz archive and populate it with files from the find command.

Note: Some graphical interfaces include a tool for managing tar.gz files without the command-line. Simply right-click the item you want to compress, mouseover compress, and choose tar.gz. You can also right-click a tar.gz file, mouseover extract, and select an option to unpack the archive.

This tutorial explains how to use the tar tool, the gzip tool, and how to utilize them together to work with tar.gz files. You are now ready to extract or unzip any tar.gz file.

Источник

How to Extract Tar Gz File in Linux — [Untar tar.gz]

This blog post will help you to get information about how to unzip tar.gz file, untar tar.gz file, and extract tar GZ file in Linux? Also, you can get a detailed guide to executing the overall process.

How to Extract Tar Gz File in Linux - [Untar tar.gz]

List of content you will read in this article:

What is TAR? [Definition]

TAR is an abbreviation for Tape ARchive. This command was primarily developed to fulfill the purpose of creating archives and storing the files on magnetic tape. Hence, the name Tape Archive.

The tar command helps you to generate several tar archives as it converts as many files as you want into archives. When we talk about the tar command, it can be used in ample ways. You can use it to add files to the archive, delete files, or extract tar archives. The list is pretty long.

Being a techie, it is highly evident that you are already familiar with the .tar.gz files.

These files are commonly known as ‘tarballs’. They are used by Linux, macOS, or even Windows users for backups or data archival.

Now, there are various methods to compress tar files. One of the most used methods to compress a file is Gzip. Moreover, whenever you compress the tar archive with gzip, it ends with .tar.gz or .tgz extension.

Besides, if you are a Windows user, you may need to download the 7zip tool to extract tar.gz file in Linux. A lot of such third-party applications are also available in the market. They do come with a drawback, that is, they do not work every time.

In this article, we are going to make you familiar with some ways to unzip/untar/extract tar.gz archives in both Linux and Windows.

Читайте также:  Установка пакетов pip linux

How to extract tar.gz file in Linux?

It is a simple process to extract tar.gz file in Linux.

Before that, take a look at the meaning of these symbols:

1. x: This option is used to extract the files.

2. v: It means Verbose. It helps to list the files in the archive.

3. z: This is used to uncompress a file.

4. f: You can easily keep a name for the file by using this option.

To start with, if the file is compressed by a gzip compressor, you can apply the following command:

In this command, filename.tar.gz is the name of the archive that you want to unpack tar.gz file. Additionally, if you want to seek more information about the files, you may use the -v option. Here, -v stands for Verbose. Take a look:

Easy, right? But somehow if your work impedes and you don’t get the desired results, follow another method.

How to unzip .tar.gz file without gzip?

Follow the below-given procedure to unzip .ta.gz file without gzip command.

$ tar xvzf file.tar.gz -C /path/to/somedirectory

Here, -C is used to mention the particular path to store the file.

  • The next command is to extract a .doc file from the .tar.gz file. Take a look at the command below:

$ tar -xvzf file.tar.gz test.doc

tar -xf archive.tar.gz file1 file2

  • This command is specifically used for files. If you want to extract some directories, use the following command:

tar -xf archive.tar.gz dir1 dir2

Sometimes you get an error message like this:

tar -xf archive.tar.gz README

It implies that the files that you want to extract don’t exist.

  • Moving on, if you want to list the content of your tar.gz file, then use the below-mentioned command:

Well, these were some of the commands to extract tar.gz files in Linux.

The next segment talks to you about extracting tar.gz files in Windows. Let’s see how!

How to untar tar.gz files in Windows?

If you are a Windows user, here are a few steps for you to follow so that you can easily extract/untar tar gz file.

Step 1. Tap on Start on your Windows

Step 2. Now, go to the Command Prompt and click right. Choose Run as Administrator option

Step 3. Enter this command in the command prompt: tar -xvzf C:\PATH\TO\FILE\FILE-NAME.tar.gz -C C:\PATH\TO\FOLDER\EXTRACTION

You can add any desired path to store your files. After you press enter, all the files will be extracted to the path that you mention.

If you do not wish to use the command line method, don’t worry. There is another solution. You can simply head towards the File manager and click right on the file that you wish to extract. Choose the Extract option.

Conclusion

In a nutshell, tar.gz files or tarballs are used to archive data and backups. It is necessary to decompress and extract these files in order to get your work going.

There are specific ways and methods to conclude your task through various steps and commands.

As you have seen, this article assists you to extract tar.gz file [unzip tar.gz file, untar tar.gz file], whether you are a user of Linux or Windows.

We hope that the information provided in this article helps you in the best possible way.

Keep learning. Keep evolving.

People are also reading:

Источник

Оцените статью
Adblock
detector