linux dd data input-output commands -----

dd

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.

grammar

dd [options] Parameters

Options

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 to lowercase characters
ucase: to convert lower case characters to upper case characters
swab: byte swapping each pair of input
noerror: error does not stop
notrunc: not truncate the output file
sync: filling each input block to the ibs bytes, and the gap filled with a null character (NUL).
-Help: display help information
-version: Display version information

Command interpreter

[root@linus ~]# dd if=/dev/zero of=/root/233.txt  bs=1M count=1
记录了1+0 的读入
记录了1+0 的写出
1048576字节(1.0 MB)已复制,0.00103718 秒,1.0 GB/

This command creates a file size of 1M 233.txt, where the parameters explained:

if: the representative of the input file. If you do not specify if, by default it will read input from stdin.
of: the representative of the output file. If you do not specify of, the default will be the default stdout output.
bs: represents the bin size in bytes.
count: represents the number of blocks to be copied.
/ dev / zero: is a character device, will continue to return a zero byte (\ 0).

Common examples

1. Data backup and restore
1.1 backup data Disc

[root@linus ~]# dd if=/dev/sda1 of=/dev/sda2	#将sda1整盘备份到sda2
[root@linus ~]# dd if=/dev/sda1 of=/backup/1 	#将sda1整盘备份到/backup下的1文件
[root@linus ~]# dd if=/dev/sda1 | bzip2  >/backup/1.bz2 #将sda1压缩并备份到/backup下的1文件

Disc Data Recovery 1.2

dd if=/dev/sda2 of=/dev/sda1
dd if=/backup/1 of=/dev/sda1
bzip2 -d  /backup/1.bz2 | dd of=/dev/sda1

2. Backup MBR partition table
2.1 backup

dd if=/dev/sda1 of=/backup/2 bs=512 count=1	#备份sda1开始部分512字节到指定文件

2.2 recovery

dd if=/backup/2 of=/dev/sda1	#将备份的数据恢复到sda1的开始部分

3. Backup memory data

dd if=/dev/mem of=/backup/3

4. destroy disk

dd if=/dev/zero of=/dev/sda1 

5. Test disk access speed

dd if=/dev/zero of=/root/4 bs=10M count=100
Published 15 original articles · won praise 5 · Views 843

Guess you like

Origin blog.csdn.net/qq_42534026/article/details/104223345