How to extract tar gz linux

Extract tar.gz File in Linux or Unix using tar

I have downloaded a file called foo.tar.gz from the Internets. How do I extract tar.gz file under Linux / UNIX like operating systems using command line options?

A tarball (tar.gz file) is nothing but compressed tar archive. 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.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements tar
Est. reading time 2m

Initially, tar archives were used to store files conveniently on magnetic tape. The name “Tar” comes from this use; it stands for tape archiver. Despite the utility’s name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files as archives. The tar command is available on Linux (CentOS/RHEL/Fedora/Debian/Ubuntu and all other distros), BSD (OpenBSD/NetBSD/FreeBSD), Apple macOS, HP-UX, AIX, and other Unix-like operating systems. This page shows how to extract tar.gz file using command line.

Syntax to extract .tar.gz file

The syntax is as follows:

Extracting tr.gz. file

To extract one or more members from an archive, enter:
$ tar -zxvf < file.tar.gz >
If your tarball name is backup.tar.gz, enter the following at a shell prompt to extract files:
$ tar -zxvf backup.tar.gz
To extract resume.doc file from backup.tar.gz tarball, enter:
$ tar -zxvf backup.tar.gz resume.doc
Where,

  1. -z : Work on gzip compression automatically when reading archives.
  2. -x : Extract tar.gz archive.
  3. -v : Produce verbose output i.e. display progress and extracted file list on screen.
  4. -f : Read the archive from the archive to the specified file. In this example, read backups.tar.gz archive.
  5. -t : List the files in the archive.
  6. -r : Append files to the end of the tarball.
  7. —delete (GNU/Linux tar only) : Delete files from the tarball.

In order to untar a tar file, the -x (for extract) and -f options are needed.

Extracting an entire archive

To extract an entire archive, specify the archive file name only, with no individual file names as arguments.
tar -zxvf backup.tar.gz

List files in archive

To view a list of the files within a tarball, issue the following command, enter:
$ tar -tvf backup.tar.gz

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

How to create a tarball

tar command used to create a Tape ARchive. The resulting file is known as a tarball in Unix world. Let us see how to create a tarball using tar command. The following would create an archive file called data.tar from the three files named file1.txt, file2.txt and file3.txt that are located in the current directory:
tar -cvf data.tar file1.txt file2.txt file3.txt
One can use the tar command to make archives from the contents of one or more directories. For example, the contents of two directories named /etc/ and /home/vivek/Documents/ could be archived into a file named dump.tar with the following:
tar -cvf dump.tar /etc/ /home/vivek/Documents
In this example, create an archive named data.tar.bz2 of the files /etc/ directory that is compressed using gzip:
tar -cvzf files.tar.gz /etc/

How to add files to an existing tarball

Pass the -r option. For example, the following would append a file named resume.doc to file.tar:
tar -rf file.tar resume.doc

How delete files from a tarball

Pass the —delete option to GNU/tar command which allows specified files to be completely removed from a tarball. Thus, for example, the files pic1.png and pic2.png can be removed from file.tar with the following:
tar -f file.tar —delete pic1.png pic2.png

Conclusion

We have shown you how to extract tar.gz file from the command line. The commands should work on Linux and Unix-like systems. For more info see tar command help page here and here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

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

By Jithin on January 5th, 2017

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.

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.

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

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

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

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.

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

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

Nice explanation. Very helpful. Thanks a lot.

Источник

Как распаковать tar bz2 xz gz архивы в Linux

Шпаргалка по распаковке tar архивов.

Для распаковки tar-архивов через командную строку используется утилита tar.

Полезно знать, что архивы в формате tar имеют расширение файлов .tar . Также в Linux распространены архивы, которые имеют дополнительное сжатие другими программами. Например, архивы .tar.bz2 , .tar.gz и другие. Все эти архивы можно распаковать утилитой tar.

Распаковка tar

Для распаковки архива в формате .tar в текущую директорию выполните команду:

Распаковка tar.bz2, tar.bzip2, tbz2, tb2, tbz

Распаковка tar.xz, txz

Распаковка tar.gz, tgz

Распаковка tar.lzma

Пояснение опций

x — распаковать архив.
v — Verbose-режим (вывод на экран дополнительной информации во время распаковки).
f — выполнить распаковку архива из файла.
j — вызвать bzip2 для распаковки архива.
z — вызвать gzip
J — вызвать xz

Распаковка в определенную директорию

Чтобы распаковать архив в определенную директорию используется опция -C или —directory , например:

Примечание: директория должна существовать.

Заключение

Мы рассмотрели базовый набор команд, который можно использовать для распаковки различных видов tar-архивов. Существуют также еще некоторые типы архивов, но они менее распространены.

Источник

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

Home » DevOps and Development » 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.

  • 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.

To decompress a file, use the gunzip command:

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

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:

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

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:

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

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:

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:

Источник

Читайте также:  Tuya smart приложение для windows
Оцените статью