看shell的时候看到case这块,突然想到可以实现一个脚本实现多种压缩文件的解压。于是实现了下面的脚本。
当然,这个还是有限,感兴趣的可以自己再扩充:
我只是实现了 .rar .tar .zip .tar.gz .tar.bz2压缩文件的解压。
#########################################################################
# Copyright (c) 2010-~zhouyongfei
#
# This source code is released for free distribution under the terms of the GNU General Public License
#
#
# Author: alen Chou
# File Name: smartdecompress.sh
# Description:
#########################################################################
#!/bin/bash
ftype=`file "$1"`
case "$ftype" in
"$1: RAR archive"*)
rar x "$1";;
"$1: POSIX tar archive"*)
tar xvf "$1" ;;
"$1: Zip archive"*)
unzip "$1" ;;
"$1: gzip compressed"*)
tar zxvf "$1" ;;
"$1: bzip2 compressed"*)
tar jxvf "$1" ;;
*) echo "File $1 can not be uncompressed with smartzip" echo "usage: ./smartdecompress.sh [filename] (be sure the mode is 0755)"
echo " be sure File type is one of the follow:"
echo " .rar .tar .zip .tar.gz .tar.bz2" ;;
esac
|
阅读(1181) | 评论(0) | 转发(0) |