您的位置:首页 > 其它

写一个脚本 从键盘让用户输入几个文件,脚本能够将此几个文件归档压缩成一个文件

2015-08-25 16:06 281 查看
vim mytar.sh

#!/bin/bash
#
read -p "Three files:" file1 file2 file3
read -p "Destination:" DEST -->指定压缩存放目录及文件名称
read -p "Compress[gzip|bzip2|xz]:" COMP  -->输入压缩的格式
case $COMP in
gzip)
tar -zcf ${DEST}.tar.gz $file1 $file2 $file3
;;
bzip2)
tar -jcf ${DEST}.tar.bz2 $file1 $file2 $file3
;;
xz)
tar -cf ${DEST}.tar $file1 $file2 $file3
xz  ${DEST}.tar
;;
*)
echo "Unknow."
exit 9
;;
esac


测试脚本:
[root@localhost test]# pwd
/mnt/test
[root@localhost test]#chmod +x mytar.sh
[root@localhost test]# ./mytar2.sh
Input Three files:test1.txt test2.txt test3.txt
Destination:/mnt/test/test
Compress[gzip|bzip2|xz]:gzip
[root@localhost test]# ls
mytar.sh   test2.txt  test.tar.gz
test1.txt  test3.txt


本文出自 “小曾” 博客,请务必保留此出处http://zengxin.blog.51cto.com/6098070/1688086
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: