dd - convert and copy a file dd创建指定大小的文件,还可以用来备份,更多详细信息,可以参考man dd页面
命令格式:dd if='input_file" of="output_file" bs="block_size" count="number"
参数说明:
- if:if=FILE 读取FILE替换标准输入
- of:of=FILE 写入到FILE替换标准输出
- bs:bs=BYTES 一次读取和写入多少字节
- count:count=BLOCKS 复制多少输入块
创建指定大小的文件
[root@rhel6164 ~]# dd if=/dev/zero of=/tmp/bigfile bs=1M count=1000
#/dev/zero作为输入文件,会一直输出0,这里创建了一个1000M的文件
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 11.1137 s, 94.4 MB/s
[root@rhel6164 ~]# du -sch /tmp/bigfile
1001M /tmp/bigfile
1001M total
备份数据
[root@rhel6164 ~]# ll /etc/passwd
-rw-r--r-- 1 root root 2373 Jun 10 2014 /etc/passwd
[root@rhel6164 ~]# dd if=/etc/passwd of=/tmp/passwd.bakup
4+1 records in
4+1 records out
2373 bytes (2.4 kB) copied, 5.5885e-05 s, 42.5 MB/s
#因为我这里没有指定bs的大小,默认是512Byte,因为上面是2373Byte,所以是上面有4个完整的bs,有一个不是完整的bs
[root@rhel6164 ~]# dd if=/etc/passwd of=/tmp/passwd.bakup1 bs=100
23+1 records in
23+1 records out
2373 bytes (2.4 kB) copied, 5.0871e-05 s, 46.6 MB/s
#这里指定了bs为100Byte,然后就是23个完整的bs