DD Command Explanation

Source: Internet
Author: User

function:
DD is a command in Unix and Unix-like systems, with the main functions of converting and assigning files. On Unix and Unix-like systems, hardware device drivers (such as hard disks) and special device files (such as/dev/zero,/dev/random) appear in the file system as normal files, as long as the corresponding functions are implemented in their respective drivers, DD You can also read or write these files. DD can also be used in the boot sector of the backup hardware to obtain a certain amount of random data, and so on some tasks. DD programs can also process data when copied. For example, convert a byte order, or convert between ASCII and Ebxcdic encoding.

Usage:

The
command line statement for DD differs from other programs because its command option format is option = value, DD reads from standard input by default, and writes to standard output, which can be used to select if (input file) and the of (output file).

Concept of Block:

A
block is a unit that measures a read, write, and convert bytes, and command-line options can specify a different block size for input/read (IBS) and Output/write (OBS) options that override the IBS and OBS options, The default block size for input and output is 512 bytes (the traditional disk block and the size of the POSIX-defined block) for the Count option to replicate. The Read (skip) option and the Write (seek) option are all in blocks. The conversion operation is also thin "convert block Size (CBS)" Effect. represents w twice times, b represents 512 times times, k represents 1024 times times, M represents 1024x1024 times, G represents 1024x1024x1024 times

Use:

* Data conversion: DD can replicate data between files, devices, partitions, and volumes. Data can be entered and exported from anywhere, but there are significant differences in output to the partition. In addition, the data can be used with the CONV option to accommodate the media during transmission. How the last block has an unexpected length, attempting to copy the entire disk using CP may be missed, and DD may succeed. The source file and the destination disk should be the same size. DD if =/dev/sr0 of=mycd.iso BS =2048 conv =noerror, sync//Create ISO disk image from CD-ROM DD if =/dev/sda2 of =/DEV/SDB2 bs=4096 Conv=noerror//clones one partition to another DD if =/dev/ad0 of =/dev/ad1 bs=1m conv noerror//clone HDD ad0 to Ad1 NoError If an error occurs, the program continues, and sync fills each block to the specified byte * Backup and Recovery master Boot record: The master boot record can be repaired. The master boot record can be converted to a file or transferred from the total. DD if =/dev/fd0 of =mbrboot.img bs=512 count=2//To replicate the first two sectors of a floppy disk: DD if =/DEV/SDA of =mbr.img bs =512 count = 1//Create a mirror of the entire x86 master boot record (including MS-DOS partition table and MBR bytes) dd if =/dev/sda of =mbr_boot.img bs=446 count = 1//create mirror with master boot record code only * Data modification: DD can modify data directly DD If=/dev/zero of=path/to/file bs=512 count=1 conv=notrunc//Empty bytes overwrite the first 512 bytes of the file, notrunc means that the output file is not scaled down, and if there is a file, only the corresponding byte of data is modified. If it does not exist, a 512-byte file is created. When the output file of DD is a block device, there is no effect. DD if=/dev/sdb2 of=partition.img bs=4096 counv=noerror//Copy the disk partition into a disk image file in a different partition. * Disk Erase: For security reasons, it is sometimes necessary to erase discarded disks. dd IF=DEV/SDA//Check the drive for data and output it to standard output DD If=/dev/zero of =/DEV/SDA bs=4k//erase disk with 0 * Drive Performance Benchmarks: Benchmark drives and analyze the performance of continuous system reads and writes using 1024-byte blocks: dd if =/dev/zero bs=1024 count=1000000 of=file_1gb dd if =FILE_1GB of=/dev/null bs=1024 * Generate files with random data DD if=/dev/urandom of=myrandom bs=100 count=1//using kernel random number driver, generate files with 100 random bytes * Convert files to uppercase dd if =filename of=filename1 conv=ucase * Create empty files of any size DD If=/dev/zero of=mytestfile.out Bs=1 seek =1g//create 1G sparse files, or increase the size of existing files.

Parameters:

if = input file (or device name).

of = output file (or device name).

IBS = Bytes Reads bytes bytes At a time, that is, the number of bytes read into the buffer.

Skip = Blocks skips the ibs*blocks block that reads into the beginning of the buffer.

Obs = bytes Writes bytes bytes At a time, that is, the number of bytes written to the buffer.

BS = bytes Sets the number of bytes in the read/write buffer (equal to the set IBS and OBS).

CBS = bytes Converts bytes bytes at a time.

Count = Blocks only copies the input blocks blocks.

CONV = ASCII converts the EBCDIC code to an ASCII code.

Conv = EBCDIC converts ASCII code to EBCDIC code.

CONV = IBM converts ASCII code to alternate EBCDIC code.

CONV = Blick Converts the change bit to a fixed character.

CONV = Ublock Converts the fixation into a change bit

CONV = UCase the letter from lowercase to uppercase.

CONV = LCase The letter from uppercase to lowercase.

CONV = Notrunc does not truncate the output file.

CONV = swab swaps each pair of input bytes.

CONV = NoError does not stop processing when an error occurs.

Conv = sync puts the size of each input record to the size of the IBS (filled with IBS).

DD command in detail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.