Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to decompress multiple compressed files in Deepin at the same time in Linux". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Files can be extracted on the Deepin command line in the Linux system, and multiple tarball files can be extracted at the same time using the Deepin command line. So how to extract multiple compressed files at the same time in Deepin in Linux?

$ls

Backup1.tar backup2.tar backup3.tar

We need to decompress them all together. What should we do?

Let's start with a brief explanation of the use of tar. The tar command was originally used to read and write files from a tape device (tar is short for Tape ARchiver). We can only specify the file name to put in the compressed file or extract (such as tar x myfineonthe.tape). 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 (later) parameters are treated as part of the compressed file mentioned above.

Tar-x-f backup.tar myfile.txt

# or use the following more common syntax

Tar xf backup.tar myfile.txt

Now let's get back to our previous problem: extract the three backup1.tar backup2.tar backup3.tar files under the current directory at the same time. Some friends may want to use tar xf *. Tar, let's take a look at the implementation results:

$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 here? Shell replaces * .tar by matching the file name, and the above line is actually equivalent to:

Tar xf backup1.tar backup2.tar backup3.tar

From our previous explanation of the use of tar, we know that the command we use here means "extract backup2.tar and backup3.tar from the compressed file backup1.tar." The execution can be successful only if there is a corresponding file name in the compressed file backup1.tar.

Solution: unzip the files one by one from the compressed files.

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

For tarname in * .tar; do

Tar xf "$tarname"

Done

Let's talk about the two basic concepts of loop and for- loop. A loop is a structure used to repeat its internal code before a condition is met. The loop stops when this condition is met, and the code outside it continues to execute. a for-loop is a loop structure that sets a variable to values in a list one at a time and repeats until the list runs out.

Here, the for- loop repeatedly calls the execution tar xf as a parameter that matches the filename of *. Tar. In this way, we decompress the compressed files "automatically" one by one.

Another common file format is ZIP. The command to extract the ZIP file is unzip. There is the same problem here: unzip accepts only one option to specify the ZIP file.

It can be solved in the same way:

For zipfile in * .zip; do

Unzip "$zipfile"

Done

There is another approach to the unzip command: it can be read in a shell-like style (pattern) to specify the ZIP file name. To prevent shell from interpreting these styles, you need to use quotation marks .unzip (instead of shell) to explain * .zip:

Unzip "* .zip"

# you can also use the following approach that looks clearer:

Unzip\ * .zip

This is the end of the introduction of "how to decompress multiple compressed files in Deepin at the same time in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report