Show progress of dd command
This was the third time I was going to do a
dd of something without knowning how long it would take, so I Googled how to see the progress of
dd which I could not find in the manual.
Turns out the answer is sending
dd a signal to output progress. To send the INFO (USR1 in Linux) signal to
pkill to send a signal to the first matched
pkill -USR1 -n -x dd
After sending the INFO/USR1 signal,
dd will output the progress on stderr.
Even though this is not in the manual page (
man dd), it is part of the info pages (
info coreutils dd):
Sending an 'INFO' signal to a running `dd' process makes it print I/O statistics to standard error and then resume copying. In the example below, 'dd' is run in the background to copy 10 million blocks. The 'kill' command makes it output intermediate I/O statistics, and when 'dd' completes normally or is killed by the 'SIGINT' signal, it outputs the final statistics.
To get a read-out every 30 seconds, I opened another terminal and started:
watch -n 30 'pkill -USR1 -n -x dd'
Update: archeydevil commented on the use of
pidof and pointed out the preferred use of
pkill. I've changed the examples above to reflect this. The old examples were:
kill -USR1 `pidof -s dd` watch -n 30 "kill -USR1 `pidof -s dd`"
Please note that the new examples will check for the PID multiple times, so this means that if a new
dd is started with another PID it will be picked up and sent USR1 signals (
-n is short for
--newest). You could use
kill in combination with
pgrep to do a single lookup of the PID and give that to watch like so:
watch -n 30 "kill -USR1 `pgrep -x -n dd`"
Which would means that you would be sending a USR1 signal to any process taking the that PID number as soon as the kernel decides it needs it again. In hindsight I think sending it to new
dd commands is probably the best solution.
Update: I've been told that some terminals will send an INFO signal when you hit
CTRL+T. However, I have not been able to reproduce this.