0

When dd is done it prints a three line summary about the number of read and written segments, the total size and average writing speed. While it does its work, dd is awfully quiet.

Not too long ago (mea culpa) I discovered that I can make dd print the three line summary while it is still doing work by emitting SIGUSR1. Ever since I do

dd <magic incantation> &
watch kill -USR1 $!

The problem is, that with this the three lines of dd's summary are not left aligned. Each following line starts at the column the previous line ended. So I'm guessing dd prints a newline character, but not a carriage return and whatever watch uses to print output expects carriage returns.

I tried putting | sed -e '<expression>' behind the kill command different sorts of quoting but the output I get presented does not change at all.

How can I pretty print the dd output in this scenario?

1

You don't need kill -USR1 to know where dd is at. You can use lsof to display the position of its input file descriptor. Getting parseable output is a bit abstruse, but it works. Note that the 0 is the input file descriptor; if you pass a if=… argument to dd rather letting it read from standard input, then depending on your implementation of dd, it might read from a different descriptor.

lsof -a -o -p $! -d 0 -F o | sed -n 's/^o[0-9]*t//p'

On Linux, you can get this information directly from /proc.

</proc/$!/fdinfo/0 awk '$1 == "pos:" {print $2}'

You might as well use cat instead of dd: it's often faster and it's less error-prone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.