Free Hosting Online for WorkStations

< Previous | Contents | Next >

Moving Data Directly To/From Devices

While we usually think of data on our computers as being organized into files, it is also possible to think of the data in “raw” form. If we look at a disk drive, for example, we see that it consists of a large number of “blocks” of data that the operating system sees as di- rectories and files. However, if we could treat a disk drive as simply a large collection of data blocks, we could perform useful tasks, such as cloning devices.

The dd program performs this task. It copies blocks of data from one place to another. It uses a unique syntax (for historical reasons) and is usually used this way:

Moving Data Directly To/From Devices


dd if=input_file of=output_file [bs=block_size [count=blocks]]

dd if=input_file of=output_file [bs=block_size [count=blocks]]


Let’s say we had two USB flash drives of the same size and we wanted to exactly copy the first drive to the second. If we attached both drives to the computer and they are as- signed to devices /dev/sdb and /dev/sdc respectively, we could copy everything on the first drive to the second drive with the following:



dd if=/dev/sdb of=/dev/sdc

dd if=/dev/sdb of=/dev/sdc


Alternately, if only the first device were attached to the computer, we could copy its con- tents to an ordinary file for later restoration or copying:



dd if=/dev/sdb of=flash_drive.img

dd if=/dev/sdb of=flash_drive.img


Warning! The dd command is very powerful. Though its name derives from “data definition,” it is sometimes called “destroy disk” because users often mistype either the if or of specifications. Always double check your input and output specifi- cations before pressing enter!



Top OS Cloud Computing at OnWorks: