What exactly does the dd command do?
Solution 1
dd
does a byte-by-byte copy from the source to the destination, with an optional conversion specified by the conv
argument. It performs reads and writes as specified by the *bs
and *flag
options, with the range defined by the count
, skip
, and seek
options.
what happens if the specified output file is too small to be turned into the specified input file?
If of
is too small to contain if
then the data is truncated to fit. Note that if of
is a regular file then it is overwritten.
Solution 2
I won't even try to summarize what is in these links, but you may find them useful (or too-much-info) ... They are both from Unix & Linux (stackexchange)
- dd vs cat — is dd still relevant these days?
- When is dd suitable for copying data? or, when are read() and write() partial?
Related videos on Youtube
ICoffeeConsumer
Updated on September 18, 2022Comments
-
ICoffeeConsumer almost 2 years
A few days ago I was delighted to find out that it's not all that difficult to write an iso image to a USB without the help of a third-party program explicitly designed to do so. But the command (or program) that facilitates this - dd - puzzles me.
According to Wikipedia it's designed to copy and convert raw data, but honestly I find this definition very equivocal and vague. I understand that it lets you turn one piece of data into another, but what happens if the specified output file is too small to be turned into the specified input file?
dd if=giant_file of=tiny_file
Also, when I create a bootable USB with an image file, the USB attains a filesystem type of isofs, but if I write an archive or executable to the drive, it retains its regular filesystem type.
Any clarification of what the dd command really does or how it works on a lower level would be much appreciated. Thanks!
-
tvdo almost 12 years
of
is overwritten even if it's not a file - this is a very nice way to (accidentally?) destroy a partition/drive! That's why it's very important to double and maybe triple check the destination if it's a drive/partition, to make sure you have the right one. -
Ignacio Vazquez-Abrams almost 12 yearsTechnically it writes into the object rather than overwriting it.
-
ICoffeeConsumer almost 12 yearsThanks for the answer. What if you don't include any arguments, but do something like
dd if=executable of=archive.tar
, assuming they are both the same size. Will the archive be transformed flawlessly into the executable? -
Ignacio Vazquez-Abrams almost 12 yearsIt will do a byte-for-byte copy from
executable
toarchive.tar
512 bytes at a time. It will not turn the binary into an archive.