dd 命令是一个比较重要而且比较有特色的一个命令,它能够让用户按照指定大小和个数
的数据块来复制文件的内容。
用法:
dd [参数]
dd if="input_file" of="output_file" bs="block_size" count="number"
参数 | 作用 |
---|---|
if | 输入的文件名称 |
of | 输出的文件名称 |
bs | 设置每个“块”的大小 ,若为指定则预设是512bytes(一个sector的大小) |
count | 设置要复制“块”的个数,即多少bs的意思 |
举例一:将/etc/passwd备份到/tmp/passwd.bak当中
root@tu-virtual-machine:~# dd if=/etc/passwd of=/tmp/passwd.bak
5+1 records in
5+1 records out
2847 bytes (2.8 kB, 2.8 KiB) copied, 0.000177938 s, 16.0 MB/s
root@tu-virtual-machine:~# ll /etc/passwd /tmp/passwd.bak
-rw-r--r-- 1 root root 2847 8月 21 09:37 /etc/passwd
-rw-r--r-- 1 root root 2847 8月 21 18:08 /tmp/passwd.bak
/etc/passwd的文件大小为2847bytes,因为没有设置bs,所以默认是512bytes为一个单位,5+1表示5个完整的512bytes,1个未满512bytes的块。