Start dd and show progress every X seconds

dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
Adjust "sleep X" to your needs. *NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while).
Sample Output
cyrusza@OMGWTF:/mnt/storage/share/downloads$ dd if=devastation.tar.gz of=dev-backup.tar.gz & pid=$! && sleep 15 && while kill -USR1 $pid; do sleep 15; done
[1] 22929

223969+0 records in
223968+0 records out
114671616 bytes (115 MB) copied, 15.0148 s, 7.6 MB/s
457235+0 records in
457234+0 records out
234103808 bytes (234 MB) copied, 30.0572 s, 7.8 MB/s
676833+0 records in
676832+0 records out
346537984 bytes (347 MB) copied, 45.077 s, 7.7 MB/s
918865+0 records in
918865+0 records out
470458880 bytes (470 MB) copied, 60.1207 s, 7.8 MB/s
1130209+0 records in
1130208+0 records out
578666496 bytes (579 MB) copied, 75.1381 s, 7.7 MB/s
1180668+1 records in
1180668+1 records out
604502352 bytes (605 MB) copied, 78.6036 s, 7.7 MB/s
[1]+  Done                    dd if=devastation.tar.gz of=dev-backup.tar.gz
-bash: kill: (22929) - No such process
cyrus@OMGWTF:/mnt/storage/share/downloads$

3
By: cyrusza
2010-12-02 15:07:18

2 Alternatives + Submit Alt

What Others Think

What about a do ... until ?
DaveQB · 407 weeks and 1 day ago
If i remember well, in bash the until loop is only the negation of the same while condition, and you can do only "until xxx do yyy", not "do yyy until xxx".
cyrusza · 407 weeks and 1 day ago
The pv way is nice if pv is there, but this is handy for when it isn't.
splante · 388 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: