Chinaunix首页 | 论坛 | 博客
  • 博客访问: 813049
  • 博文数量: 92
  • 博客积分: 1498
  • 博客等级: 上尉
  • 技术积分: 993
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-18 18:31
文章分类

全部博文(92)

文章存档

2013年(2)

2012年(3)

2011年(3)

2010年(61)

2009年(23)

分类: LINUX

2010-07-27 10:43:31

看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


阅读(1111) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~