有时候部署环境有很多安装包, 如果一个一个地解压缩实在太麻烦了, 可以用 shell 批量进行解压缩. 命令如下:
- [[email protected] ~]# vi tar.sh
- #! /bin/bash
- # 标称是 Shell 脚本
- cd /usr/local/src/
- # 进入保存源码包的目录
- ls *.tar.gz> /usr/local/src/ls.log
- # 把所有以. tar .gz 结尾的文件名覆盖写入 ls.log 文件
- ls *.tgz>> /usr/local/src/ls.log
- # 把所有以. tgz 结尾的文件名追加写入 ls.log 文件
- file=$(cat /usr/local/src/ls.log)
- # 读取 Is.log 文件中的内容, 赋子变量 file
- for i in $file
- #for 循环, 每次循环把变量 file 中的一个文件名
- do
- tar -zxf $i
- #解压缩毎个压缩文件
- done
- rm -rf /usr/local/src/ls.log
- # 删除临时文件 ls.log
- # 以上是脚本的内容
- [rootBlocalhost ~]# chmod 755 tar.sh
- # 赋予 tar.sh 文件执行权限
- [[email protected] ~]
- ./tar.sh
- # 执行这个脚本
来源: http://www.bubuko.com/infodetail-3149339.html