[Update – June 2017] – as nvoss noted in the comments, as of coreutils version 8.24 (published 2 years ago), dd
supports a nice status=progress
option which does exactly what this post is about… At last! 🙂
dd
is one tool I really love and one that really scares the hell out of me. It’s so powerful you have to show him respect, otherwise you’ll end up destroying all your precious data!
One thing it’s not very good at however is to show you some info on what’s going on and, most of all, how fast your files are being shredded to pieces never to come back again 🙂
So, say we’re using dd
like this:
dd if=/path/to/input_file of=/path/to/output_file bs=4096
To get the usual
N record in N record out N bytes copied, M seconds, P transfer rate
we all learned to love, you can just
sudo killall -USR1 $DD_PID
from within another terminal and dd
will display its statistics to the terminal you launched it from. Of course, you may add some
watch --interval=10 killall -USR1 $DD_PID
to update statistics at regular intervals.
But this is just boring.. What about some sort of progress bar? 😉
The trick is to break down dd
in its input and output parts, and throw a pv
in the middle, like this:
dd if=/path/to/input_file bs=4096 | pv -s SIZE_OF_INPUT_FILE | dd of=/path/to/output_file bs=4096
where SIZE_OF_INPUT_FILE
is your best estimate of input_file
size (M
and G
may of course be used for megabytes and gigabytes), and voilà , you get a progress bar that looks like wget
‘s!
pv
comes as a package for a lot of Linux distributions, so it should be no issue to (apt-)get it.
You may also have stat
guess the file size for you, like it’s written here, but in case you’re dealing with /dev/sdX
and such you’re out of luck, as stat
will always tell your file is 0 bytes long.
As of coreutils v8.4, dd has a built in status bar:
LikeLike
hey, thanks for the heads up! I checked and it looks like it’s from v8.24 on (4 years after this post). Post updated 🙂
LikeLike
Thanks so much for taking the time to blog this awesome tip @micheluzzo.
I do however have a question.
I’m using dd on a mac, but if I include ‘status=progress’ to the code, then it fires back ‘unknown operand status.’ Is it just not available on mac terminal or am I doing it wrong?
Here is the code I used:
sudo dd if=/dev/zero of=/dev/disk3 conv=noerror bs=1024 status=progress
Thanks in advance!
LikeLike
Hey Kyler, thanks for the kind words 🙂
It looks like the version of dd that comes with MacOS doesn’t have that flag, so you’ll have to use pv as I described on this post. To install, just run brew install pv, and you’re good to go!
LikeLike