dd Command: Tutorial & Examples
Copy data between block devices
dd command in Linux is a command-line utility used to convert and copy files. It can be used to copy and convert data from one file or block device to another, while also
allowing various options to be specified, such as the block size and count. It can also be used to create a disk image of a partition or an entire disk. The basic syntax of the
dd if=input-file of=output-file [options]
if option specifies the input file, and the
of option specifies the output file. Additional options include bs (block size), count (number of blocks), seek (number of
blocks to skip at the beginning of the input file), and conv (format conversion options).
For example, the command
dd if=/dev/sda of=backup.img creates a copy of the entire
/dev/sda disk, which is saved in the file
backup.img. It can also be used for low level
copying, for example to clone a drive, or for forensic purposes.
It is important to be very careful when using this command as it can cause data loss if used improperly. For example, if you want to overwrite a device with zeros to delete the data irrevocably, you can use the following command:
dd if=/dev/zero bs=1M | pv | dd of=/dev/sde bs=1M
This reads zeros from the special device file
/dev/zero and writes them to the disk
/dev/sde overwriting all existing data on it. The
pv between the pipes displays how much data has already been written. Note also the block size parameter
bs=1M, which reads and writes the data in
1MB chunks to speed up the process.