I am using dd command for block level copy and just found out that there’s no built in way to check the progress. How do I use the Linux or Unix dd command while coping /dev/sda to /deb/sdb and display a progress bar when data goes through a pipe? How do I monitor the progress of dd on Linux?
dd is a free and open source command-line tool for Linux, and Unix-like operating systems. It is mainly used to convert and copy files. Being a program mainly designed as a filter dd usually does not provide any progress indication. This page shows how to show progress copy bar on Linux operating system.
Linux dd Command Show Progress Copy Bar With Status
You need to use gnu dd command from coreutils version 8.24 or above to use the following option. The syntax is as follows to show progress copy bar with dd command:
dd if=/path/to/input of=/path/to/output status=progress
Let us pass the progress option to see periodic transfer statistics using GNU dd command:
# dd if=/dev/sda of=/dev/sdb bs=1024k status=progress
No need to use sudo. I used sudo because I was trying to read and clone a USB stick.
Use pv command monitor the progress of dd command and see status
Another option is to use pv command which allows you to see the progress of data through a pipeline. You need to install pv command as described here. Once installed, type the following commands to see the status bar. Please note that if standard input is not a file and no size was given with the -s option, the progress bar cannot indicate how close to completion the transfer is, so it will just move left and right to indicate that data is moving. It will also show average MB/s rate:
Copy /dev/sda to to /dev/sdb:
pv -tpreb /dev/sda | dd of=/dev/sdb bs=64M
pv -tpreb /dev/sda | dd of=/dev/sdb bs=4096 conv=notrunc,noerror
You can create a progress bar and display using the dialog command as follows:
(pv -n /dev/sda | dd of=/dev/sdb bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0
Examples: Use gnu dd command from coreutils version 8.24 or above only
Here is another example from my Mac OS X/MacOS:
$ sudo gdd if=ZeroShell-3.6.0-USB.img of=/dev/disk5 bs=1024k status=progress
How do you monitor the progress of dd on Linux?
If you are using an older version of dd or cannot install the pv command, try the following simple one-liner bash shell while loop/command:
## 1. first start dd as usual ## sudo dd if=/dev/sdc of=/tmp/demo.img bs=4M ## 2. Open another terminal or tab ## ## 3. find pid of dd command ## pidof dd ### <--- say pid is 21145 ps aux | grep -w dd ## 4. Run bash/sh while loop as follows ## while sudo kill -USR1 21145 ; do sleep 10 ; done ## 5. Switch back to terminal where dd was started ##
The dd command is wonderful, and there are various ways to display a progress indicator with dd. You learned how to monitor the progress of dd using the inbuilt status=progress option to the dd command. Another option is to use the pv tool. Finally, you learned that how to show dd progress in Linux without using pv or status= progress option. See GNU dd man page here for more info.