4
2
I see examples online all the time of using dd in combination with pv to show progress... But, something I don't understand is that pv is perfectly capable of doing the task entirely on it's own. So, why use dd as well? Is there some advantage dd provides that pv doesn't?
Examples using both dd and pv. Some of these are really complicated...
dd if=/dev/sda | pv | dd of=/mnt/backup.img
dd if=/dev/sda | pv -s 10G | dd of=/mnt/backup.img
dd if=/dev/sda | (pv -s `fdisk -l /dev/sda | grep -o '[0-9]*\{1\} MB' | awk '{print $1}'`m) | dd of=/mnt/backup.img
You can acheive the same thing using pv alone by doing
pv /dev/sda > /mnt/backup.img
"Some of these are really complicated" - Seems like a good enough reason to just use pv. I searched on the topic, most results, seem to indicate there isn't a built in way to report the progress. So either dd has added this feature since those statements were made. But pv also seems to communicate between two processes.
– Ramhound – 2015-06-11T15:50:05.297can't find a soure, but I'm pretty sure pv stands for Pipe-View, since it just seems to show statistical data on piping/redirecting operations. In fact, I'm certian that the pv command listed would work in exactly the same way without the pv invocation, other than that you wouldn't get the nice progress output. – Frank Thomas – 2015-06-11T15:51:34.657
I didn't like the title @barlop made since I know what
pvis doing, I just don't understand whatddis doing thatpvisn't. So, I changed the title to "what does dd do that pv doesn't?" – Drew Chapin – 2015-06-11T16:08:52.780@Ramhound, but in my example,
pv /dev/sda > /mnt/backup.img,pvis not reading from a pipe? It's reading from the device file. – Drew Chapin – 2015-06-11T16:10:01.320@druciferre - Your other three examples do pipe the stdout. Its been awhile, and I forget what function
>performs but I do know the results in communication between two processes. – Ramhound – 2015-06-11T16:14:44.297ockquote>
is output redirection. same as piping but to a file instead of a subsequent process. the PV does nothing more than cat the file, and count bytes and give you a progress bar. its the > in that command thats actually moving data.
– Frank Thomas – 2015-06-11T16:16:37.2472
@druciferre: You should take a look at this related interesting question: Is dd better than cat?
– Karan – 2015-06-11T16:32:31.720@FrankThomas - Redirect, i knew it was something, had to write my own limited kernel with pipe and redirect support was never able to get both working :$ – Ramhound – 2015-06-11T16:41:13.817
@FrankThomas pv is indeed 'pipe viewer' – Sirex – 2015-06-11T19:59:32.103
@Karan +1 that is a fantastic link. I would note that many have pointed out a difference between cat and dd being that dd you can configure block size. Though pv can also. One of the answers there shows a way to monitor block size with the ltrace command. You can specify block size with e.g.
pv -s 2M– barlop – 2015-06-11T23:04:13.890yes your new title "What does dd do that pv doesn't?" is much better than any prior one. – barlop – 2015-06-11T23:16:23.293
This is a brilliant question and the current answer to it seems to be incorrect. It deserves a better, more comprehensive answer. – Hashim – 2017-10-18T23:48:56.550