Linux dd command [command]

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/zztingfeng/article/details/90727451

Linux dd command for reading data is converted and output.
dd reads from the standard input file or data, converts the data according to the specified format, and then output to a file, device or standard output.

Parameter Description:
    IF = File Name: Enter the file name, the default is standard input. That is, to specify the source file.
    of = file name: output file name defaults to the standard output. That is, specify the destination file.
    ibs = bytes: byte read into bytes, i.e., a block size of bytes specified bytes.
    obs = bytes: one byte output bytes, i.e., a block size of bytes specified bytes.
    bs = bytes: while providing read / output block size bytes bytes.
    cbs = bytes: byte conversion bytes that specify a translation buffer size.
    skip = blocks: blocks skipped blocks from beginning of the input file and then begins copying.
    seek = blocks: blocks skipped blocks from beginning of output file before starting copying.
    count = blocks: copy only blocks block, the block size is equal to the number of bytes specified ibs.
    conv = <key>, can have the following 11 kinds of keywords:
    Conversion: transform file with the specified parameters.
    ascii: Conversion ebcdic to ascii
    ebcdic: convert ascii to ebcdic
    IBM: convert ascii to Alternate ebcdic
    Block: each row is converted to a length of cbs, shortfall with spaces
    unblock: that the length of each row are cbs, shortfall by spaces filling
    lcase: uppercase characters to lowercase characters
    ucase: convert lower case characters to upper case characters
    swab: each switch input byte
    noerror: not stop error
    notrunc: not truncate the output file
    sync: filling each input block to the ibs bytes, empty less than some ( NUL) character is lacking.
    --help: display help information
    --version: display version information

For example:

1. The local / dev / hdb Disc backup to / dev / HDD
dd IF = / dev / hdb of = / dev / HDD
2. backup / dev / hdb overall image data file to the specified path
dd if = / dev / HDB = of / the root / Image
3. restore the backup file to the specified disk
dd = IF / the root / Image of = / dev / hdb
4. backup / dev / hdb overall data, and use with gzip compressed to save specified path
dd IF = / dev / HDB | the gzip> /root/image.gz
5. the compressed backup file into the specified tray
the gzip -dc /root/image.gz | dd of = / dev / HDB
6. the backup disk MBR information 512 bytes in size to the specified file starting
dd IF = / dev / HDA = of / the root / Image BS = 512. 1 COUNT =
COUNT =. 1 only refers to a block copy; bs = 512 refers to the block size of 512 byte.
Recovery:
dd = IF / the root / Image of = / dev / HDA
7. The backup floppy
dd IF = / dev / fd0 = disk.img COUNT of BS. 1 = = 1440K
(i.e., the block size is 1.44M)
8. The copy of the contents of memory to the hard disk
dd IF = / dev / MEM = of / the root / mem.bin = BS 1024
(designated block size 1k)
9. Copy the contents of the optical disk to the specified folder, and to save the file cd.iso
dd IF = / dev / CDROM (HDC) = of / the root / cd.iso
10. The partition swap file size increases
Step 1: Create a size 256M file:
dd = IF / dev / ZERO of = / = BS 1024 the swapfile COUNT = 262144
step two: the swap file into the file:
the mkswap / the swapfile
third step: to enable this swap file:
the swapon / the swapfile
IV step: edit / etc / fstab file, the automatic loading at each power swap file:
/ Defaults the swapfile swap swap 0 0
11. the disk data destruction
dd if = / dev / urandom of = / dev / hda1
Note: the use of random hard disk data to fill in some necessary occasions can be used to destroy data.
12. The read and write speed of the hard disk test
dd IF = / dev / ZERO COUNT = 1024 BS = 1000000 = of / the root / 1Gb.file
dd = IF / the root / 1Gb.file BS = 64K | dd of = / dev / null
by two or more command output command execution time can be calculated disk read and write speed.
13. Determination of the optimal disk block size:
dd = IF / dev / ZERO COUNT = 1024 BS = 1000000 = of / the root / 1Gb.file
IF = dd / dev / ZERO COUNT = 2048 BS = 500000 = of / the root / 1Gb.file
dd IF = / dev / ZERO COUNT = 4096 BS = 250000 = of / the root / 1Gb.file
dd IF = / dev / ZERO BS = 8192 count = 125000 of = / root / 1Gb.file
command output shown by comparing the time of execution of the above command, to determine the optimal block size system.
14. The hard disk repair
dd if = / dev / sda of = / dev / sda
after a long time when the hard disk (for example 1, 2 years) is not used are placed, the generated magnetic fluxpoint disk. When the head read these regions will encounter difficulties and may cause I / O errors. When this affects the first sector on the drive, it can cause a hard scrapped. Top of the order is likely to make these data back to life. And the process is safe and efficient.
15.dd commands from startup disk usb
dd XXX.iso of IF = = / dev / SDB 1M BS =
the root user or sudo, with the above command must be unloaded before u disk, sdb your u disk, bs = 1M block is large numerical size, the back, write speed is relatively little faster, but not infinite, I usually choose 2M, note that after executing the command completed very soon, but still u disk flash, no flash, etc., safely removed.

Guess you like

Origin blog.csdn.net/zztingfeng/article/details/90727451