Displaying a progress bar while using dd

[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.


2 thoughts on “Displaying a progress bar while using dd

    • 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 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s