Linux tips-Batch pressurization of tar files

Source: Internet
Author: User

Because Linux tar commands do not support batch decompression, many netizens have compiled a lot of shell commands that support batch decompression and collected them for your sharing.

First:

 
For tar in * .tar.gz; do tar xvf $ tar; donefor tar in * .tar.bz2; do tar xvf $ tar; done

Type 2: Decompress all tar.gz files under a folder with a tarcommand

 
Ls * .tar.gz | xargs-N1 tar xzvf

I personally think this is the most convenient.

Third:

 
Find-maxdepth 1-name "*. bz2" | xargs-I tar xvjf {}

This command can decompress all bz2 files in the current directory. maxdepth indicates the search depth, and 1 indicates that only the current directory is searched.

Fourth:

 
For I in $ (LS *. Tar); do tar xvf $ I; done

Exclude specified directory:

 
Tar zcvf linuxany. tgz -- exclude = '*/log/*' linuxany/

Exclude specified files:

 
Tar zcvf linuxany. tgz -- exclude = '*/*. log *' linuxany/
Problem:
I want to decompress the tar file in batches and use tar -Xvf * An error occurs in. Tar and the system prompts "not ". Found In Archive ". There are many solutions, such as writing a script. Why does tar not support this wildcard syntax? Is there a special reason? I tried gzip to support gzip. -D * .Tar.gz.
Answer:
Wildcard is a shell Solution
For example
Tar -Xvf *. Tar
When tar is actually executed, tar receives
Tar -Xvf A.tar B .tar C.tar ...
If the current directory does not contain tar, tar receives the '*. Tar' parameter.
Different from win, all characters in Linux can be Composition File name, that is, the directory does not exist *. Tar file
To prevent * .Taris interpreted as a.tar by shell. B .tar C.tar...
It can be enclosed in single quotes.

when you use tar to unbind an archive, the syntax is
tar -xvf
.
is one or more member files in myfiles.tar. If there are multiple wildcard characters, you can use wildcard characters.
don't worry about me first. I know, you know. However, your problem is that you used
tar -xvf *. tar
As mentioned above, tar receives
tar -xvf a.tar B .tar c.tar ...
here, you can extract B .tar from a.tar. c.tar ...

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.