[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Useless use of "dd"



* 2021-07-01 20:43:09-0700, David Christensen wrote:

> To "take an image", the script invokes dd(1) and pipes the output to
> gzip(1), copying raw device octets to a file. To "restore an image",
> the process is reversed.

Sounds like the classic "useless use of dd". For general educational
purposes I remind (not necessarily you) that "dd" is just a file copying
(and conversion) tool, almost like "cat". By default "dd" is a slow
version of "cat" because it uses smaller buffers. "dd" can be made
faster by increasing its buffer size but that will not make it more than
just "cat".

So "dd" is not a special tool for accessing device files. Device files
don't need special tools. They are files. The following command:

    dd if=/dev/sdX | gzip >image.gz

is slower but functionally the same as either of these:

    gzip </dev/sdX >image.gz
    gzip --to-stdout /dev/sdX >image.gz

Usually we don't need "dd" for anything but there are some options which
are useful sometimes. For example, "dd" can report progress to standard
error stream and it can seek and limit read to some blocks or bytes.

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

Attachment: signature.asc
Description: PGP signature


Reply to: