一個shell指令碼解多個壓縮檔(改別人的代碼)

來源:互聯網
上載者:User
                         一個shell指令碼解多個壓縮檔(改別人的代碼)
    這個程式核心代碼是有linuxsir.org的tram兄寫的,主要是時限瞭解壓縮檔的功能.我加了一些代碼使他能夠壓縮目錄和解開rar檔案,這個SHELL程式還是很簡單的,我經常用他,將程式的許可權用chmod gou+x filename該為可執行,然後複製到/bin/usr下.這樣就可以使用了.呵呵.  一下就是代碼.
#!/bin/bash
if [ -d $1 ]; then
tar czvf $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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.