l 《鸟哥的 Linux 私房菜》之 “档案的压缩与打包”
l 《Linux 基础教程(1) 操作系统基础》第14章
[root@linux ~]# dd if="input_file"of="output_file" bs="block_size" \
count="number"
参数:
if :就是 input file 啰~也可以是装置喔!
of :就是 output file 喔~也可以是装置;
bs :规划的一个 block 的大小,如果没有设定时,预设是 512bytes
count:多少个 bs 的意思。
范例:
范例一:将 /etc/passwd 备份到/tmp/passwd.back 当中
[root@linux ~]# dd if=/etc/passwd of=/tmp/passwd.back
3+1 records in
3+1 records out
[root@linux ~]# ll /etc/passwd /tmp/passwd.back
-rw-r--r-- 1 rootroot 1746 Aug 25 14:16 /etc/passwd
-rw-r--r-- 1 rootroot 1746 Aug 29 16:57 /tmp/passwd.back
# 仔细的看一下,我的/etc/passwd 档案大小为 1746 bytes,因为我没有设定 bs ,
# 所以预设是 512 bytes 为一个单位,因此,上面那个 3+1 表示有 3 个完整的
# 512 bytes,以及未满 512 bytes 的另一个 block 的意思啦!
# 事实上,感觉好像是 cp 这个指令啦~
范例二:备份 /dev/hda 的 MBR
[root@linux ~]# dd if=/dev/hda of=/tmp/mbr.back bs=512count=1
1+0 records in
1+0 records out
# 这就得好好了解一下啰~我们知道整颗硬盘的 MBR 为 512 bytes,
# 就是放在硬盘的第一个sector 啦,因此,我可以利用这个方式来将
# MBR 内的所有数据都纪录下来,真的很厉害吧! ^_^
范例三:将整个 /dev/hda1 partition 备份下来。
[root@linux ~]# dd if=/dev/hda1 of=/some/path/filename
# 这个指令很厉害啊!将整个partition 的内容全部备份下来~
# 后面接的 of 必须要不是在 /dev/hda1 的目录内啊~否则,怎么读也读不完~
# 这个动作是很有效用的,如果改天你必须要完整的将整个 partition 的内容填回去,
# 则可以利用 dd if=/some/fileof=/dev/hda1 来将数据写入到硬盘当中。
# 如果想要整个硬盘备份的话,就类似Norton 的 ghost 软件一般,
# 由 disk 到 disk ,嘿嘿~利用dd 就可以啦~厉害厉害!
你可以说, tar 可以用来备份关键数据,而 dd 则可以用来备份整颗 partition 或 整颗 disk ,很不错啊~不过,如果要将数据填回到 filesystem 当中,可能需要考虑到原本的 filesystem 才能成功啊!
NAME
dd - convert and copy a file
SYNOPSIS
dd [OPTION]...
DESCRIPTION
Copy a file, converting and formatting according to the options.
bs=BYTES
force ibs=BYTES and obs=BYTES
cbs=BYTES
convert BYTES bytes at a time
conv=KEYWORDS
convert the file as per the commaseparated keyword list
count=BLOCKS
copy only BLOCKS input blocks
ibs=BYTES
read BYTES bytes at a time
if=FILE
read from FILE instead of stdin
obs=BYTES
write BYTES bytes at a time
of=FILE
write to FILE instead of stdout
seek=BLOCKS
skip BLOCKS obs-sized blocks atstart of output
skip=BLOCKS
skip BLOCKS ibs-sized blocks at startof input
--help display this help and exit
--version
output version information andexit
BLOCKS and BYTES may be followedby the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K1024,
MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and soon for T, P, E, Z, Y. Each KEYWORD maybe:
ascii from EBCDIC to ASCII
ebcdic from ASCII to EBCDIC
ibm from ASCII to alternatedEBCDIC
block pad newline-terminatedrecords with spaces to cbs-size
unblock
replace trailing spaces incbs-size records with newline
lcase change upper case to lowercase
notrunc
do not truncate the output file
ucase change lower case to uppercase
swab swap every pair of inputbytes
noerror
continue after read errors
sync pad every input block withNULs to ibs-size; when used
with block or unblock, pad with spacesrather than NULs
Note that sending a SIGUSR1 signal to a running a€?dda€? process makesit print to standard error the number of records
read and written so far, then to resume copying.
$ dd if=/dev/zeroof=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill$pid
10899206+0 records in 10899206+0records out
AUTHOR
Written by Paul Rubin, David MacKenzie, and Stuart Kemp.
REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>.
COPYRIGHT
Copyright ?? 2004 Free Software Foundation, Inc.
This is free software; see the source for copyingconditions. There is NO warranty; noteven for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
SEE ALSO
The full documentation for dd is maintained as a Texinfo manual. If the info and dd programs are properly
installed at your site, the command
info coreutils dd
should give you access to the complete manual.
dd (coreutils) 5.2.1 April 2006 DD(1)
[root@DB-GATE-16 tmp]# man dd
DD(1) User Commands DD(1)
NAME
dd - convert and copy a file
SYNOPSIS
dd [OPTION]...
DESCRIPTION
Copy a file, converting and formatting according to the options.
bs=BYTES
force ibs=BYTES and obs=BYTES
cbs=BYTES
convert BYTES bytes at a time
conv=KEYWORDS
convert the file as per the commaseparated keyword list
count=BLOCKS
copy only BLOCKS input blocks
ibs=BYTES
read BYTES bytes at a time
if=FILE
read from FILE instead of stdin
obs=BYTES
write BYTES bytes at a time
of=FILE
write to FILE instead of stdout
seek=BLOCKS
skip BLOCKS obs-sized blocks atstart of output
skip=BLOCKS
skip BLOCKS ibs-sized blocks at startof input
--help display this help and exit
--version
output version information andexit
BLOCKS and BYTES may be followedby the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K1024,
MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and soon for T, P, E, Z, Y. Each KEYWORD maybe:
ascii from EBCDIC to ASCII
ebcdic from ASCII to EBCDIC
ibm from ASCII to alternatedEBCDIC
block pad newline-terminatedrecords with spaces to cbs-size
unblock
replace trailing spaces incbs-size records with newline
lcase change upper case to lowercase
notrunc
do not truncate the output file
ucase change lower case to uppercase
swab swap every pair of inputbytes
noerror
continue after read errors
sync pad every input block withNULs to ibs-size; when used
with block or unblock, pad withspaces rather than NULs
Note that sending a SIGUSR1 signal to a running a€?dda€? process makesit print to standard error the number of records
read and written so far, then to resume copying.
$ dd if=/dev/zeroof=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill$pid
10899206+0 records in 10899206+0records out
AUTHOR
Written by Paul Rubin, David MacKenzie, and Stuart Kemp.
REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>.
COPYRIGHT
Copyright ?? 2004 Free Software Foundation, Inc.
This is free software; see the source for copyingconditions. There is NO warranty; noteven for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
SEE ALSO
The full documentation for dd is maintained as a Texinfo manual. If the info and dd programs are properly
installed at your site, the command
info coreutils dd
should give you access to the complete manual.
dd (coreutils) 5.2.1 April2006
联系客服