tar解压过程中在console显示简易进度条
2016-06-07 15:09
211 查看
本脚本用于在tar命令解压文件过程中,在console中显示简易的进度条,是根据解压出的文件总的大小和当前已经解压的文件大小来进行进度的显示,程序比较简易,普适性不是太强,很多变量可以以参数形式传递,这里不加优化,仅供作为笔记和参考而已
#!/bin/sh #显示进度的总格数 total_process=100 #当前进度格数 current_process=0 #百分比 percent=0 #文件大小 total_size=455000 #当前文件大小 current_size=0 #用于记录上一次的进度 old_process=0 print_progress () { incomplete_process=$((${total_process}-${current_process})) if [ ${incomplete_process} -lt 0 ]; then incomplete_process=0 current_process=${total_process} percent=100 fi #输出已升级部分,用>表示 printf "\rProgress:[%.${current_process}d" | tr '0' '>' #输出未升级部分,用' '表示 printf "%.${incomplete_process}d]" | tr '0' ' ' #输出当前百分比 printf "${percent}%%" } display () { while true do #统计当前已解压文件大小 current_size=$(du -s target | awk '{printf $1}') percent=$((${current_size}/(${total_size}/100))) # echo ${percent} current_process=$((${percent}\*${total_process}/100)) # echo ${current_process} if [ ${current_process} -eq 0 ]; then print_progress elif [ ${current_process} -ne ${old_process} ]; then print_progress old_progress=${current_process} fi #以tar进程结束来结束本进程 ps -ef | grep "tar jxvf" | grep -v "grep" > /dev/null if [ $? -ne 0 ]; then echo "Update Over" break fi done } tar jxvf file.tar.gz -C ./target > /dev/null & display
相关文章推荐
- Eclipse常用链接
- loadrunner之 学习九:分析结果,给出报告
- java 中获取ServletContext中常用的方法
- JAVA面试中的多线程问题
- loadrunner之 学习八:运行与监控
- android点击手机返回键触发事件
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 剑指offer(四十一)之翻转单词顺序列
- Objective-C编程语言中nil、Nil、NULL、NSNull有什么区别
- 浅谈jQuery 选择器和dom操作
- 从心理学角度分析什么样的人适合软件开发?
- 地址无关代码
- linux下查看运行进程
- loadrunner之 学习七:controller创建负载测试场景
- iOS 面向切面编程与typhoon框架
- 第十五周阅读程序(3)
- Lucene笔记(3)
- leetcode 25. Reverse Nodes in k-Group
- loadrunner之 学习六:将结果写入日志文件
- 关于AndroidStudio的CheckStyle插件