One shell script resolves multiple compressed files (change others' code)

Source: Internet
Author: User
Tags unpack
One shell script resolves multiple compressed files (change others' code)
The core code of this program is written by tram at linuxsir.org. It mainly aims to understand the function of compressing files in a limited time. I added some code to enable him to compress the Directory and unlock the rarfile. This shell program is very simple. I often use it to execute the program permission using chmod Gou + x filename, then copy to/bin/usr. in this way, you can use it. haha. here is the code.
#! /Bin/bash
If [-d $1]; then
Tar czvf limit 1.tar.gz $1
Echo this is a dir
Exit 0;
Fi
Unpack = 1
If [$ {1 # *.} = bz2]; then
Temp =$ {1% .*}
If [$ {temp ##*.} = tar]; then
Tar jxvf $1
Unpack = $?
Echo this is a tar.bz2 package
Else
Bunzip2 $1
Unpack = $?
Echo this is a bz2 package
Fi
Fi
# Echo ${1 ##*.}
If [$ {1 # *.} = zip]; then
Unzip $1
Unpack = $?
Fi
If [$ {1 # *.} = RAR]; then
RAR x $1
Unpack = $?
Fi
If [$ {1 # *.} = GZ]; then
Temp =$ {1% .*}
If [$ {temp ##*.} = tar]; then
Tar zxvf $1
Unpack = $?
Echo this is a tar.gz package
Else
Gunzip $1
Unpack = $?
Echo this is a GZ package
Fi
Fi

If [$ {1 # *.} = tar]; then
Tar xvf $1
Unpack = $?
Echo this is a tar package
Fi

If [$ unpack = 0]; then
Echo success!
Else
Echo maybe it is not a package or the package is damaged?
Fi

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.