Linux Bash使用进度条迭代文件夹
发布时间:2020-12-13 19:35:31 所属栏目:Linux 来源:网络整理
导读:我正在写一个小脚本来处理文件夹. 运行时间很长,所以我想添加一个进度条. 这是迭代: for file in */do #processing here,dummy code sleep 1done 拥有一个计数器并知道文件夹的数量将是一个解决方案. 但我正在寻找更通用和更短的解决方案…… 我希望有人会
我正在写一个小脚本来处理文件夹.
运行时间很长,所以我想添加一个进度条. 这是迭代: for file in */ do #processing here,dummy code sleep 1 done 拥有一个计数器并知道文件夹的数量将是一个解决方案. 我希望有人会有个主意. 朱利安 编辑: 我得到了这个解决方案,它做我想要的,并且是真正的图形化: #!/bin/bash n_item=$(find /* -maxdepth 0 | wc -l) i=0 for file in /* do sleep 1 #process file i=$((i+1)) echo $((100 * i / n_item)) | dialog --gauge "Processing $n_item folders,the current is $file..." 10 70 0 done 但是,我会保留fedorqui的解决方案,而不是全屏. 非常感谢您的宝贵时间 解决方法
根据我们在
How to print out to the same line,overriding previous line?发布的结果,我得到了这个结果:
#!/bin/bash res=$(find /* -maxdepth 0 | wc -l) echo "found $res results" i=1 for file in /* do echo -n "[" for ((j=0; j<i; j++)) ; do echo -n ' '; done echo -n '=>' for ((j=i; j<$res; j++)) ; do echo -n ' '; done echo -n "] $i / $res $file" $'r' ((i++)) sleep 1 done 例 $./a found 26 results [ => ] 2 / 26 /boot [ => ] 16 / 26 /root (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |