2016-06-07 59 views

回答

1

有很多写循环的方法。我有点喜欢:

yes | sed 5q | while read r; do sleep 1; printf .; done; echo 

但你真的不想要一个循环;你想保留打印进度条,直到拷贝完成,所以你想要的东西,如:

progress() { while :; do sleep 1; printf .; done; } 

copy_the_files & # start the copy 
copy_pid=$!  # record the pid 
progress &  # start up a process to draw the progress bar 
progress_pid=$! # record the pid 
wait $copy_pid # wait for the copy to finish 
kill $progress_pid # terminate the progress bar 
echo 

或者是(你应该更换的睡眠5'命令复制文件)

#!/bin/bash 

copy_the_files() { sleep 5; kill -s USR1 $$; } 
progress() { while :; do sleep 1; printf .; done; } 
copy_the_files & 
progress & 
trap 'kill $!; echo' USR1 
wait 
0

它可能会帮助你!

import time 

print "Copying files .." 
time.sleep(1) 
print "." 
time.sleep(1) 
print "." 
time.sleep(1) 
print ".." 
time.sleep(1) 
print "" 
print "File copy complete" 
1

在Python中,你可以做这样的事情:

from time import sleep 
from sys import stdout 

Print = stdout.write 
Print("Copying files..") 
for x in xrange(4): 
    Print(".") 
    sleep(1) 
print "\nFile copy complete." 

在每次迭代它打印一个新.

经过快速搜索,我发现这article这给出了一个很好的解释如何复制文件/目录,同时更新进度栏。