dd is a very old command. It was published over 50 years ago in 1974 for Unix. This age makes the syntax of its commands quite unusual. Given that this command is frequently used to overwrite partitions and entire storage devices the unusual nature of its command syntax is dangerous. It’s a rite of passage for every Linux Sysadmin to dd
over something viable, destroying it.
There are now more modern commands that can perform the same job as dd
using much more standard syntax.
Writing an ISO to a partition or device
This job occurs when you have a Linux ISO and want to write it over a USB partition or the entire device. The dd
command looks like the following:
dd if=linux.iso of=/dev/sda1 bs=4MB status=progress
if=
Input file or what is supplying the dataof=
Output file or where the data is getting written tobs=4MB
Block sizestatus=progress
Print the status of the write operation
Using cp
The cp
command is capable of performing this task as well:
cp linux.iso /dev/sda1
Using cat
The cat
command will print the contents of an input and send it to standard out. This means that we can simply cat
the iso file onto the destination:
cat linux.iso > /dev/sda1
The >
redirects the output from cat
, standard output, to be written to a file, partition, or device. The only problem with this command is that it will not print any status information.
You can use the pv or pipe viewer command to give the status of the write:
cat linux.iso | pv > /dev/sda1
Using pv
You can also simply use the pv
command as another replacement for dd
:
pv linux.iso -Y -o /dev/sda1
-Y
This synchronizes the buffers after every write operation making the status bar more accurate for slow disks-o
This specifies the output
Bonus - Creating an arbitrary file with head
The other main use I put dd
to is to create a large file when I need one. I use the following command to create a 1GB file:
dd if=/dev/zero of=big.file bs=1MB count=1024 status=progress
if=/dev/zero
Input data from/dev/zero
of=big.file
Output file or where the data is getting written tobs=1GiB
Block sizecount=1
How many blocks to writestatus=progress
Print the status of the write operation
The input, /dev/zero
is an endless and very rapid stream of zeros. These are nulls (binary zeros, not the ASCII kind i.e. “0”). This means that running this command will create a 1GB file full of the same character.
The head
command will print the beginning number of lines, characters, or bytes of an input. This means that we can use it on /dev/zero
:
head -c 1G /dev/zero > big.file
-c 1G
head will only write the first 1GB of data from/dev/zero