Copying Files ( Part 2 )

The dd command is a utility for copying files or entire partitions at the bit level.
dd [OPTIONS] OPERAND
This command has several useful features, including:
  • It can be used to clone or delete (wipe) entire disks or partitions.
  • It can be used to copy raw data to removable devices, such as USB drives and CDROMs.
  • It can backup and restore the MBR (Master Boot Record).
  • It can be used to create a file of a specific size that is filled with binary zeros, which can then be used as a swap file (virtual memory).
Let's examine the following example, the dd command creates a file named /tmp/swapex with 50 blocks of zeros that are one megabyte in size:
sysadmin@localhost:~$ dd if=/dev/zero of=/tmp/swapex bs=1M count=50 
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.825745 s, 635 MB/s
The dd command uses special arguments to specify how it will work. The following illustrates some of the more commonly used arguments:
​⁠​‌‌⁠⁠⁠⁠​
ArgumentDescription
if
Input File: The input file to be read from.
dd if=/dev/zero of=/tmp/swapex bs=1M count=50 
The example reads from the /dev/zerofile, a special file containing an unlimited number of zeros.
of
Output File: The output file to be written.
dd if=/dev/zero of=/tmp/swapex bs=1M count=50
bs
Block Size: The block size to be used. By default, the value is considered to be in bytes. Use the following suffixes to specify other units: KMG, and T for kilobytes, megabytes, gigabytes and terabytes respectively.
dd if=/dev/zero of=/tmp/swapex bs=1M count=50
The example uses a block size of one megabyte.
count
Count: The number of blocks to be read from the input file.
dd if=/dev/zero of=/tmp/swapex bs=1M count=50
The example command reads 50 blocks.
Note this!
No block size or count needs to be specified when copying over entire devices. For example, to clone from one hard drive (/dev/sda) to another (/dev/sdb) execute the following command:
dd if=/dev/sda of=/dev/sdb

Comments