dd command: how to use it and main applications

Last update: 19/08/2024

DD

El dd command It is considered one of the most powerful utilities of Linux. Although the meaning of these letters is Data Definition, the double "D" makes it commonly receive names as striking as it is "disk shredder" o "disk duplicator". In reality, it is a tool for copying and converting data at the block level, although it has more uses.

In this article we are going to review all aspects of the command dd that any Linux user should know, from their basic syntax even their most prominent applications, including copying files, backing up and restoring disk partitions, or creating bootable USB drives.

It must be said that the command dd It should be used with great caution. If used without carrying out the necessary verifications, it may end up causing irreversible data loss. For this reason you have to pay maximum attention when working with it.

Command syntax dd

Among the most common options within the dd command syntax, the following should be highlighted:

  • bs=: To determine the size of the block that dd will read or write (for example, bs=4M).
  • conv=: To specify conversion options.
  • count=: To set the number of blocks that dd is going to copy
  • if=: File or input device (input file).
  • of=: File or output device (output file).
  • seek=: To skip a specific number of blocks or bytes while reading the output file.
  • skip=: To skip a specific number of blocks or bytes while reading the input file.
  • status=progress: To show the progress of the operation in real time.
Exclusive content - Click Here  How to Install Windows Server 2008 Step by Step

Practical uses of the command dd

dd command

Let's look at some more practical applications of the dd command and how to work on them. These are just some examples of common use, since Its real possibilities are much broader:

Create disk images

This is one of the most frequent uses of the command dd: the creating disk or partition images, which is done by copying bit by bit its content. Very useful for creating backup copies. In the following example, the source device is origin.txt and the one of destination, destination.txt.

sudo dd if=/origin.txt of=/destination.txt

Clone disks

That is, copying the entire contents of a disk and saving it to another location. An example: to copy the entire contents of the disk sda1 a sda2, you have to use the command as follows:

sudo dd if=/sda1 of=/sda2

Create a bootable USB drive

Another common use of the command dd is that of creating bootable USB drives from ISO images. For this, it is necessary specify the ISO file as the input file (if) and the USB drive as the output file (of). Here is another example:

sudo dd if=linux_x.iso of=/dev/sda bs=3M status=progress

In this case, linux_x.iso represents the ISO image of the Linux distribution, while /dev/sda It is the USB drive. Besides, bs=3M tells us the size of the block (3 megabytes), while status=progress shows the progress of the command. Sometimes this progress is displayed with the image of a bar.

Exclusive content - Click Here  How to Hide the Taskbar in Windows 10?

Skip bytes or characters when reading input file

Here is an example of using the utility skip: to skip a specific number of bytes or characters when reading the input file. It is used when it is necessary to exclude certain parts of the file. In this example, the first 200 bits:

sudo dd if=abc.txt of=zyx.txt skip=200

Erase a block device

Finally, a resource that is very convenient in certain situations. For example, when we have to sell or pass a disk to someone and we want to make sure that its previous content is completely inaccessible. Question of privacy. This operation is executed through two commands, as we illustrate in this example:

sudo dd if=/dev/zero bs=1M of=/dev/sda

This first step reduces the existing data on the device to a simple sequence of zeros. For the operation to be complete, you must fill the rest of the disk with random data:

sudo dd if=/dev/random bs=1M of=/dev/sda

Conclusion

In short, we can affirm that the command dd es an essential tool in Linux when it comes to things related to copying, cloning and converting data at a low level. Among many other things, it is used for creating disk images or securely cleaning disks, as we have seen.

Exclusive content - Click Here  How to Set a Background Image in Windows 7

Other practical applications are to compress the data read by the command dd, copy content from a CD or DVD, make partial or full backups, convert uppercase to lowercase or vice versa, etc. It is certainly worth learning how to use this command.

In any case, it is a powerful weapon that you have to know how to handle with great precision and care, as it can overwrite and even delete data without prior notice.