0

When I copy a hard drive I often use the dd command

I have one question about monitoring.

To see the progress of the copy I do like this

sudo dd if=$source of=$pathToUsb bs=4M conv=fdatasync status=progress

and I get the following message:

2969567232 octets (3,0 GB, 2,8 GiB) copiƩs, 22 s, 134 MB/s

if i want to retrieve only the number of bytes how can i proceed ?

sudo dd if=$source of=$pathToUsb bs=4M conv=fdatasync status=progress > capture.txt 2>&1

I also tried this

sudo dd if=$source of=$usb bs=4M conv=fdatasync 2>&1 | awk 'END {print ($0+0)}'

But it doesn't work

Any ideas ?

kramer
  • 111

1 Answers1

1

If I understand the question, you just one the first column of the dd output printed. The following pipes stderr and stdout to stdbuf to force output into 1 char buffer sizes so that the piping does not buffer a 4K page at a time. The tr replaces the line carriage return with a newline so that cut can extract lines at a time, and the cut selects field one of the output, namely the byte count from dd.

dd if=/dev/zero of=/dev/null bs=1M status=progress 2>&1 | stdbuf -o1 tr '\r' '\n' | cut -d' ' -f1