The input device is /dev/sdb and the output file is disk.img.
Read and write in 4 MiB blocks and show progress. The device name has been checked before execution.
Which GNU dd command is appropriate?
In dd, if is the input file and of is the output file. Reversing them when a device is involved can destroy data, so verify both paths first.
Detailed explanation
dd if=/dev/sdb of=disk.img bs=4M status=progressCorrect. It reads /dev/sdb into disk.img with a 4 MiB block size and progress reporting.
Correct. It reads /dev/sdb into disk.img with a 4 MiB block size and progress reporting.
dd if=disk.img of=/dev/sdb bs=4M status=progressIncorrect. It writes the image back to the device, reversing the requested direction.
Incorrect. It writes the image back to the device, reversing the requested direction.
dd /dev/sdb disk.img bs=4MIncorrect. dd requires input and output operands such as if= and of= in this form.
Incorrect. dd requires input and output operands such as if= and of= in this form.
cp disk.img /dev/sdbIncorrect. cp does not express the requested block size or progress reporting.
Incorrect. cp does not express the requested block size or progress reporting.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
printf '0123456789' > "$LAB_DIR/source.bin"
dd if="$LAB_DIR/source.bin" of="$LAB_DIR/copy.bin" bs=4 status=none
cmp "$LAB_DIR/source.bin" "$LAB_DIR/copy.bin" && echo MATCH
rm -r "$LAB_DIR"Expected result
MATCHKey points
- if is the input
- of is the output
- bs sets the block size
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.