dd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data. You can use this command backup whole hard drives, create a large file filled with only zeros, create and modify image files at specific points and even do conversions to upper case. dd command can strip headers, write middle of the disk, extract parts of the binary files and it can be used by the Linux kernel makefiles to make boot images. dd is capable to copy and convert magnetic tape formats, convert between ASCII and EBCDIC and swap bytes.
Syntax: dd if=infput file of=outputfile bx=byte size
Here we will create fixed 10 MB file using dd command:
[root@localhost ~]# dd if=/dev/zero of=testfile1MB bs=10485760 count=1
1+0 records in
1+0 records out
10485760 bytes (10 MB) copied, 0.253435 seconds, 41.4 MB/s
In above example, “if” means inputfile (reading) and “of” means output file (where the data has to write), “bs” is a byte size. By default, linux will take byte size (bs) as 512 bytes if they do not specify the bs option.
Yes. dd command can be used to wipe the data
Note: While executing this command you should be careful.
[root@localhost ~]# dd if=/dev/zero of=/root/anaconda bs=1024 count=5
5+0 records in
5+0 records out
5120 bytes (5.1 kB) copied, 0.00161641 seconds, 3.2 MB/s
In the above example, we are writing null to the /root/anaconda file. Above command will overwrite all file content to null.
Similarly, you can wipe the entire disk/partition and MBR content by executing following command.
[root@localhost ~]# dd if=/dev/zero of=/dev/
(where name of the disk/name of the partition)
Note: Master Boot Record resides first sector of the disk that is 512. In 512 bytes 446 byte is used for storing Boot loader information. Again be careful while trying this.
[root@localhost ~]# dd if=/dev/zero of=/dev/hda bs=446
Or you can also use urandom file.
# dd if=/dev/urandom of=/dev/hdc