Why do we use cp to copy files and not dd? (in unix-derivatives)

Solution 1:

To answer your main question, no, they do not do the same thing.

dd works on the file you specify, making it able to copy data between devices, or from a device to a file. This is commonly used for moving data if devices specifically are involved (create an iso image from a cd-rom disc for example: dd if=/dev/cdrom of=mycdrom.iso), or backup raw devices (sometimes used in RAC databases: dd if=/dev/raw/raw1 of=device_raw1)

cp is used for duplicating file content to a new file or to a new location. things you specifically want there are preservation of ownership, timestamp and mode (rights), and being able to recurse the operation (=being able to copy directories).

Source

Solution 2:

They do the same thing UNLESS you are specifying one of the options to dd which limits which bytes are copied, such as seek or skip or count or if you use the dd options to mutate bytes such as conv. If you aren't using one of these options to dd and are just using the more commonly seen options like if, of, bs then both utilities do the same thing: open both files, read from the input, write to the output until either the input is exhausted or the output cannot accept more bytes.

There is a lot of superstition about reading and writing "device" files stating that you must use dd for these, but it is just that, superstition. dd isn't doing anything different, we are just opening files and reading and writing bytes.