命令dd参数解析与使用说明

来源:互联网 发布:linux重新挂载分区 编辑:程序博客网 时间:2024/06/12 19:48

1  dd参数解析

名称:

dd - 用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。 

语法:

       dd [OPERAND]

       dd OPTION

解析:

根据operand,拷贝一个文件,并进行转换。

bs=BYTES

      设置一次读写BYTES字节(同ibs,obs);

cbs=BYTES

       一次转换BYTES字节数;

ibs=BYTES

一次读取bytes字节;

obs=BYTES

一次写入bytes字节;

conv=CONV

      将一个文件转换为制定的格,CONV可以为参数见“CONV参数说明”;

count=BLOCKS

只拷贝输入的BLOCKS块;

if=FILE

从文件FILE中读取数据(FILE可以是文件名,也可以是设备名称);

of=FILE

向文件FILE中写入数据(FILE可以是文件名,也可以是设备名称);

seek=BLOCKS

在出文件中,跳过开头的ibs*blocks块;

skip=BLOCKS

在输入文件中,跳过开头的ibs*blocks块;

iflag=FLAGS

      指定读的方式FLAGS,参见“FLAGS参数说明”

oflag=FLAGS

      指定写的方式FLAGS,参见“FLAGS参数说明”;

status=noxfer

suppress transfer statistics

 

CONV参数说明:

ascii -转换 EBCDIC 为 ASCII。

ebcdic -转换 ASCII 为 EBCDIC。

ibm -转换ASCII 为 alternate EBCDIC.

block -把每一行转换为长度为 cbs 的记录,不足部分用空格填充。

unblock-使每一行的长度都为 cbs ,不足部分用空格填充。

lcase -把大写字符转换为小写字符。

ucase -把小写字符转换为大写字符。

nocreat -不创建心的输出文件

notruncdo -不截短输出文件

swab -交换输入的每对字节。 Unlike the Unix dd, this works when an odd number of bytes are read. If the input file contains an odd number of bytes, the last byte is simply copied (since there is nothing to swap it with).

noerror -出错时不停止。

sync -把每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐。

fdatasync -physically write output file data before finishing

fsync -同上,但也要写元数据

FLAGS参数说明:

append -append  mode  (makes  sense  only  for output; conv=notrunc sug-gested)

direct 读写数据采用直接IO方式;

directory 读写失败除非是directory;

dsync  读写数据采用同步IO;

sync   同上,但是针对是元数据

fullblock 堆积满block(accumulate full blocks of input )(iflag only);

nonblack 读写数据采用非阻塞IO方式

noatime 读写数据不更新访问时间

noctty -do not assign controlling terminal from file

nofollow -do not follow symlinks

 

OPTION说明:

--help

display this help and exit

--version

output version information and exit


2  测试实例

清单1:

要把一张软盘的内容拷贝到另一张软盘上,利用/tmp作为临时存储区。把源盘插入驱动器中,输入下述命令:

[root@RedHat home]#dd if =/dev/fd0 of = /tmp/tmpfile

拷贝完成后,将源盘从驱动器中取出,把目标盘插入,输入命令:

[root@RedHat home]# dd if = /tmp/tmpfile of =/dev/fd0

软盘拷贝完成后,应该将临时文件删除:

[root@RedHat home]#rm /tmp/tmpfile

 

清单2:

    采用dd测试硬盘的读写速度

Ø  可以通过使用dd if=/dev/zero of=/file 来测试磁盘的纯写入性能。

Ø  使用dd if=/file of=/dev/null 来测试磁盘的纯读取性能。

Ø  使用dd if=/file1 of=/file2 来测试磁盘的读写性能

测试硬盘的结果如下:

(1)测试纯写入性能

<pre name="code" class="objc">root@RedHat home]# dd if=/dev/zero of=test bs=8k count=10000 oflag=direct10000+0 records in10000+0 records out81920000 bytes (82 MB) copied, 3.9123 s, 20.9 MB/s

结果为20.9 MB/s。

(1)测试纯读取性能

<pre name="code" class="objc">[root@RedHat home]# dd if=test of=/dev/null bs=8k count=10000 iflag=direct10000+0 records in10000+0 records out81920000 bytes (82 MB) copied, 0.424138 s, 193 MB/s
结果为193 MB/s。

 

原创粉丝点击