Linux tar extract all

How to extract multiple tar ball (*.tar.gz) files in directory on Linux or Unix

I have tried tar -xvf *.tar.gz command, but getting an error that read as:
tar (child): *.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
> tar: Child returned status 2
tar: Error is not recoverable: exiting now

How can I extract multiple *.tar.gz files in directory using Linux or Unix-shell prompt?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements tar with Bash/KSH
Est. reading time 3 minutes

Linux or Unix-like system use the tar command to list, test, or extract files from a tar ball archive, commonly found on Unix-like systems including macOS, FreeBSD, OpenBSD, NetBSD and Linux distros. Let us see how to extract multiple tar ball files in a dirctory.

The problem with multiple tar ball files on Linux/Unix

Assuming that you have three files in the current directory as follows:

Let us verify it with the ls command $ ls
Here are my tar balls:

To untar all *.tar.gz file, enter:
$ tar xvf *.gz
# or #
$ tar -zxvf *.tar.gz
# or #
$ tar xvf «*.gz»
# trying *.gz files #
$ tar -zxvf ‘*.gz’
Sample outputs:

Fig.01: Extract multiple .tar.gz files

Method #1: Untar and extract multiple tar ball files using bash for loop

Verify it:
ls
Sample outputs:

Method #2: Untar multiple tarballs using bash/sh/ksh pipes

The syntax is:
cat *.tar.gz | tar zxvf — -i
cat *.tgz | tar zxvf — -i
cat *.tar.xz | tar Jxvf — -i
cat *.tar.bz2 | tar jxvf — -i
Sample outputs:

NOTE: The -i option force the tar command to ignore zeroed blocks in archive (EOF). This is needed if you are using method #2.

  • 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 Extract a Tar Files To a Different Directory on a Linux/Unix-like Systems

Pass the -C dir option. For instance:

Understanding tar extracting CLI options

Where the tar command are as follows:

  • z : Filter the archive through gzip command
  • x : Extract option
  • v : Verbose output. In other words, show progress while extracting files
  • f : Filename to work on
  • i : See note above.
  • J : Filter for .xz file. See how to extract xz files for more info.
  • j : Filter for .bz2 file
  • : Read from pipe or stdin
  • C DIR_NAME : Cd in to the DIR_NAME before performing extract operations.

Wrapping up

We explained how to extract multiple tar ball files on Linux and Unix-like systems. See tar man page using the man command:
% man tar
% man bash
% help for

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

Источник

How to extract tar.xz files in Linux and unzip all files

H ow do I extract tar.xz files in Linux? Can you tell me command to unzip linux-5.6.13.tar.xz file? How can I uncompressing (or decompressing) all files in the current directory?

The tar command and xz command provides support for extracting and uncompressing tar.xz files and .txz archives under Linux operating systems.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements tar and xz commands on Linux
Est. reading time 6 minutes

How do I extract tar.xz files in Linux?

  1. Install xz using the dnf install xz on a CentOS/RHEL/Fedora Linux.
  2. Debian/Ubuntu Linux users try apt install xz-utils command.
  3. Extract tar.xz using the tar -xf backup.tar.xz command
  4. To decompress filename.tar.xz file run: xz -d -v filename.tar.xz

Installation

XZ is a set of open-source software for lossless data compressors, including LZMA and xz formats. These formats are popular among open source developers and projects due to higher compression rates than alternatives tools like gzip and bzip2. The tar command works if xz installed on the system. Hence, we must install it.

Debin/Ubuntu Linux install xz

Use the apt command/apt-get command:
$ sudo apt install xz-utils
Sample outputs:

CentOS/RHEL/Fedora Linux install xz

Open the terminal app and then run NA command/dnf command as follows:
$ sudo dnf install xz
## On an older version of CentOS/RHEL try yum ##
$ sudo yum install xz
From my CentOS 6.x box:

Installing xz on OpenSUSE/SUSE Enterprise Linux

We can use the zypper command to install xz:
$ sudo zypper install xz

OpenSUSE installing xz package for extraction purposes

Examples

Now we install xz. We can now directly use the tar command as follows for extracting a file named linux-5.6.13.tar.xz:
$ tar -xf linux-5.6.13.tar.xz
$ tar -xvf linux-5.6.13.tar.xz
$ tar -Jxvf linux-5.6.13.tar.xz
## extract tar.xz files aka .txz file ##
$ tar —xz -xf archive.txz

Extracting specific files from a tar.xz file

We extract a given file names from a backup.tar.xz file by using the following syntax:
$ tar -xf backup.tar.xz resume.pdf
$ tar -xf backup.tar.xz babys-3rd-cake-day.jpg sales.txt
Sometimes we don’t know file names in advance. Hence, we list the contents of an archive by passing the -t as follows and then unzip tar.xz files:
$ tar -tvf backup.tar.xz
## filter out tar listing option using the grep command/egrep command ##
$ tar -tvf backup.tar.xz | grep file1
$ tar -tvf backup.tar.xz | egrep ‘ file.txt | data.doc | cake.jpg ‘

Want to extract all Perl or Python source code files? Try the following option:
$ tar —wildcards ‘*.py’ -xvf webroot.tar.xz
$ tar —wildcards ‘*.pl’ -xvf centos-7-sysadmin-scripts.txz

Understanding tar command options

  • -x : Extract/get/unzip files from an archive.
  • -f archive.tar.xz : Use this archive file or device archive for extracting files
  • -J OR —xz : Filter the archive through xz command. Hence, we install xz using package manager.
  • -v : Verbose. Show progress.
  • -t : List file stored inside .tar.xz/.xz archive.
  • —wildcards : By default, wildcards don’t work as they treated or processed to by your current shell. Therefore, to extract files, use the —wildcards options. For example, extract all .webp images I would pass —wildcards ‘*.webp’ option to the tar.

How to extract .xz files using the xz command

So far, we learned to use tar for extracting. But, we can use xz command directly for as compressor and decompressor too. Tar internally calls xz itself or using API provided by libs. Let us see some tips and tricks for xz command.

Decompress .tar.xz file

$ xz —decompress filename.tar.xz
$ xz -v -d archives.tar.xz
Decompress file named mysql.sql.xz and replaced by mysql.sql:
$ xz -v -d mysql.sql.xz

Compress tarball as .tar.xz file

Compress a file named mysql.sql and replace it by mysql.sql.xz for saving disk space:
$ xz mysql.sql
The syntax is as follows for compressing per-existing tarball:
$ xz -v -z filename.tar
Alternatively, use the tar command for convenience purposes
$ tar -cv J f file1 file2
$ tar -cv J f /path/to/dir1 ./dir2
$ sudo tar -cv J f /efs/backups/14-05-2020/production-webroot.tar.xz /var/www/
$ sudo tar —xz -cvf /efs/backups/aws-us-west-www-prod-42-etc.txz /etc/

Gif 01. xz in action

Compress from stdin

$ mysqldump nixcraft-blog | xz > nixcraft-blog.sql.xz
Of coruse we can uncompress and send content to stdout for the mysql command too
$ xzcat nixcraft-blog.sql.xz | mysql nixcraft-blog
Let us uncompress tar directory from stdin sent from the nc, enter (assuming that target server-ip protected by VPN else use the ssh command):
$ nc -l -p 4242 | tar -xJvf —
On other side compress directory to stdout and send to the nc, run:
$ tar -cJvz — /var/www/html | nc server-ip-here 4242
Our final example use ssh instead of nc:
$ tar —xz -cf — /path/to/dir | ssh vivek@server1.cyberciti.biz «cat > filename.txz»
See “How To Use tar Command Through Network Over SSH Session” for more info.

  • 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

Conclusion

This quick tutorial explained how to extract and unzip popular archive formats such as .tar.xz and .txz under Linux operating systems. Remember, tar command only works if you install the xz command via the package manager. See the xz project home page and docs here.

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

Источник

How to Extract Tar Files to Specific or Different Directory in Linux

The tar utility is one of the utilities that you can use to create a backup on a Linux system. It includes many options that one can use to specify the task to achieve.

Extract Linux Tar Files Different or New Directory

One thing to understand is that you can extract tar files to a different or specific directory, not necessarily the current working directory. You can read more about tar backup utility with many different examples in the following article, before proceeding further with this article.

In this guide, we shall take a look at how to extract tar files to a specific or different directory, where you want the files to reside.

The general syntax of tar utility for extracting files:

Note: In the above first syntax, the -C option is used to specify a different directory other than the current working directory.

Let us now look at some examples below.

Example 1: Extracting tar Files to a Specific Directory

In the first example, I will extract the files in articles.tar to a directory /tmp/my_article . Always make sure that the directory into which you want to extract tar file exists.

Let me start by creating the /tmp/my_article directory using the command below:

You can include the -p option to the above command so that the command does not complain.

To extract the files in articles.tar to /tmp/my_article , I will run the command bellow:

Img 01: Extract Tar Files to Different Directory

In the above example I used the -v option to monitor the progress of the tar extraction.

Let me also use the —directory option instead of -c for the example above. It works just in the same way.

Img 02: Extract Tar Files to Specific Directory

Example 2: Extract .tar.gz or .tgz Files to Different Directory

First make sure that you create the specific directory that you want to extract into by using:

Now we will extract the contents of documents.tgz file to separate /tmp/tgz/ directory.

Img 03: Extract tar.gz or .tgz Files to Different Directory

Example 3: Extract tar.bz2, .tar.bz, .tbz or .tbz2 Files to Different Directory

Again repeating that you must create a separate directory before unpacking files:

Now we will be unpacking the documents.tbz2 files to /tmp/tar.bz2/ directory.

Img 04: Extract tar.bz2 Files to Different Directory

Example 4: Extract Only Specific or Selected Files from Tar Archive

The tar utility also allows you to define the files that you want to only extract from a .tar file. In the next example, I will extract specific files out of a tar file to a specific directory as follows:

Img 05: Extract Specific Files From Tar Archive

Summary

That is it with extracting tar files to a specific directory and also extracting specific files from a tar file. If you find this guide helpful or have more information or additional ideas, you can give me a feedback by posting a comment.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Читайте также:  Telecharger whatsapp pour pc windows
Оцените статью