Skip to content

What is dd Linux command?

The Linux dd command is a versatile tool used for copying and converting files. It allows users to create exact duplicates of data, such as disks or partitions. With dd, you can also perform tasks like disk cloning, data recovery, and low-level formatting. Additionally, dd can be used to benchmark storage devices and manipulate data in various ways. Familiarize yourself with the syntax and options of dd to leverage its capabilities effectively.

dd Syntax:

Terminal window
dd [option] [parameter]

dd Options:

OptionDescription
if=FILEread from FILE
of=FILEwrite to FILE
bs=BYTESread and write BYTES bytes at a time
count=BLOCKScopy only BLOCKS input blocks
seek=BLOCKSskip BLOCKS obs-sized blocks at start of output
skip=BLOCKSskip BLOCKS ibs-sized blocks at start of input
status=LEVELThe LEVEL of information to print to stderr; ‘none’, ‘noxfer’, ‘progress’, or ‘full’
conv=CONVERSIONconvert the file as per the comma separated symbol list

Parameters:

ParameterDescription
if=FILEinput file
of=FILEoutput file

dd Command Usage Examples:

Copying Files

Terminal window
dd if=inputfile.txt of=outputfile.txt

This command copies the contents of “inputfile.txt” to “outputfile.txt”.

Cloning a Disk

Terminal window
dd if=/dev/sda of=/dev/sdb bs=4M

This command clones the entire contents of disk “/dev/sda” to disk “/dev/sdb” with a block size of 4MB.

Creating a Disk Image

Terminal window
dd if=/dev/sdb of=disk_image.img

This command creates an image file “disk_image.img” from the contents of disk “/dev/sdb”.

Testing Disk Write Speed

Terminal window
dd if=/dev/zero of=testfile bs=1M count=1000

This command tests the write speed of the disk by writing 1GB of zeros to a file “testfile”.

Erasing Data on a Disk

Terminal window
dd if=/dev/zero of=/dev/sdc bs=4M

This command overwrites the contents of disk “/dev/sdc” with zeros, effectively erasing all data on the disk.

How do I use dd in Linux?

To use the dd command in bash, execute the following command:

Terminal window
dd if=input_file of=output_file bs=block_size count=number_of_blocks

What is the purpose of the bs option in dd?

The bs (block size) option in dd is used to specify the number of bytes to read and write at a time. This can help optimize the performance of the dd command.

Terminal window
dd if=input_file of=output_file bs=4k

How can I monitor the progress of a dd command?

You can send the USR1 signal to the dd process to make it print the current status without halting the process. Open a new terminal and execute the following command:

Terminal window
kill -USR1 $(pgrep ^dd)

How do I create a disk image using dd?

To create a disk image using dd, specify your disk as the input file (if) and a file as the output file (of). Make sure to use a block size and count appropriate for the disk size.

Terminal window
dd if=/dev/sda of=disk_image.img bs=4M

How can I wipe a disk with dd in Linux?

To wipe a disk using dd, you can write zeros or random data to the entire disk. Be cautious as this action will erase all data on the disk. Here is an example of writing random data to a disk:

Terminal window
dd if=/dev/urandom of=/dev/sdX bs=4M

How do I clone a disk with dd?

To clone a disk using dd, you need to specify the disk you want to clone as the input file (if) and the target disk as the output file (of). Be careful as this will overwrite all data on the target disk.

Terminal window
dd if=/dev/sda of=/dev/sdb bs=4M

How can I create a bootable USB drive with dd?

To create a bootable USB drive with dd, use an ISO image file as the input file (if) and the USB drive as the output file (of).

Terminal window
dd if=ubuntu.iso of=/dev/sdX bs=4M

What does the status=progress option do in dd?

The status=progress option in dd shows the progress of the operation in the terminal, providing information on how much data has been copied. It is useful for tracking the status of a long-running dd command.

Terminal window
dd if=input_file of=output_file bs=4k status=progress

Applications of the dd command

  • Creating disk images
  • Cloning disks
  • Backing up and restoring hard drives
  • Converting and formatting disks
  • Benchmarking disk performance