The dd command in Linux is a powerful utility used for low-level copying and conversion of data. It can be used for tasks such as creating disk images, copying files, and converting data formats.
Basic Syntax
dd if=<input_file> of=<output_file> [options]
Parameters
if=<input_file>: Specifies the input file (source).of=<output_file>: Specifies the output file (destination).bs=<block_size>: Sets the block size for reading and writing (default is 512 bytes).count=<number_of_blocks>: Specifies the number of blocks to copy.skip=<number_of_blocks>: Skips a specified number of blocks from the input file before starting to copy.seek=<number_of_blocks>: Skips a specified number of blocks in the output file before writing.
Common Use Cases
-
Copying a File
dd if=input.txt of=output.txt -
Creating a Disk Image
dd if=/dev/sda of=disk_image.img bs=4M -
Restoring a Disk Image
dd if=disk_image.img of=/dev/sda bs=4M -
Creating a Bootable USB Drive
dd if=path/to/iso_file.iso of=/dev/sdX bs=4M(Replace
/dev/sdXwith the actual device identifier for your USB drive.) -
Copying with a Specific Block Size
dd if=input.txt of=output.txt bs=1M count=10(This copies the first 10 megabytes of
input.txttooutput.txt.)
Important Notes
- Be very careful when using
dd, especially with theofparameter, as it can overwrite data without warning. - Always double-check the device paths to avoid data loss.
- You can use the
status=progressoption to see the progress of the operation:dd if=input.txt of=output.txt status=progress
The dd command is a versatile tool, but it should be used with caution due to its potential to overwrite data.
