How to extract multiple compressed files in Linux at the same time in Deepin

Source: Internet
Author: User
Tags command line zip

The file can be decompressed on the Deepin command line on the Linux system, and the Deepin command line can also extract multiple tarball files at the same time. So how do Linux in the Deepin simultaneous decompression of multiple compressed files?

$ ls

Backup1.tar Backup2.tar Backup3.tar

We need to unpack them all together, how do we do that?

Let's briefly explain the usage of tar. The tar command was used to read and write files from a tape device (tar is the Tape archiver). We can only specify the name of the file (such as Tar x Myfineonthe.tape) to be placed in the compressed file or extracted. You can use the-f option to tell tar that the file is not on a tape but in a file. This option accepts only one parameter-the file name of the compressed file. All other (subsequent) parameters are treated as part of the compressed file mentioned above.

Tar-x-F Backup.tar myfile.txt

# or use the more common syntax below

Tar XF backup.tar myfile.txt

Now back to our previous question: Simultaneously extract the Backup1.tar Backup2.tar backup3.tar three files below the current directory. There may be friends who want to use the tar XF *.tar, let's look at the results of their execution:

$ tar XF *.tar

Tar:backup2.tar:Not found in archive

Tar:backup3.tar:Not found in archive

Tar:exiting with failure status due to previous errors

What's going on? The Shell is replaced by a matching file name *.tar, which is actually equivalent to:

Tar XF Backup1.tar Backup2.tar Backup3.tar

From our previous explanation of the use of tar, the command we use here means "extract Backup2.tar and Backup3.tar from the compressed file Backup1.tar". Success can only be performed if the file name is available in this compressed file in Backup1.tar.

Workaround: Extract the file one by one from the compressed archive.

We are using a UNIX shell (Bash), which can be implemented using loops:

For Tarname in *.tar; Todo

Tar xf "$tarname"

Done

Here are two basic concepts of loops and for-loops. A loop is a structure used to repeat the code that is inside before a condition is met. The loop stops when the condition is met, and its external code continues to execute. The for-loop is to set a variable to each value in a list and repeat until the list is exhausted.

In this case, the for-loop calls the matching *.tar file name as a parameter repeatedly to execute the tar XF. So we'll extract the compressed file "automatically".

Another very common file format is zip. The command to extract the zip file is unzip. Here's the same problem: Unzip only accepts one option to specify a ZIP file.

The same method can be used to solve:

For ZipFile in *.zip; Todo

Unzip "$zipfile"

Done

Another approach to the unzip command is that it can read a shell-like pattern to specify a ZIP file name. To prevent the shell from interpreting these styles, you need to use quotes. Unzip (not shell) explains *.zip here:

Unzip "*.zip"

# You can also use the following seemingly clearer approach:

Unzip *.zip

The above is how linuxlinux in the Deepin at the same time to extract multiple compressed files tutorial, use this tutorial is not a one to extract the file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.