In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how Linux Deepin decompresses multiple taball files at the same time, the content is very detailed, interested friends can refer to, hope to be helpful to you.
How to extract multiple tarball files at the same time on the command line of Linux Deepin? Before the introduction, let's give an example. Suppose we have the following compressed files in the current directory:
$ls
Backup1.tar backup2.tar backup3.tar
We need to decompress them all together. What should we do?
Let's first briefly explain the use of tar. The tar command was originally used to read and write files from a tape device (tar is an abbreviation 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? 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.
The solution is simple: unzip the files one by one from the compressed file. Because we are using a UNIX shell (Bash), we can do this with 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 it 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. So 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's interpretation of these styles, use quotation marks. Unzip (not shell) will explain * .zip here:
Unzip "* .zip"
# you can also use the following approach that looks clearer:
Unzip\ * .zip on how Linux Deepin decompressed multiple taball files at the same time to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.