Chinaunix首页 | 论坛 | 博客
  • 博客访问: 23421
  • 博文数量: 8
  • 博客积分: 69
  • 博客等级: 民兵
  • 技术积分: 65
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-17 00:35
个人简介

做为一名Linux爱好者,欢迎各位加友交流..... 特别声明:因以前学习时候都是文档笔记,未写入博客.许多文章均来自网络.未标明出处的请自行查询.

文章分类

全部博文(8)

文章存档

2013年(1)

2012年(7)

我的朋友
最近访客

分类:

2012-08-12 17:32:36

原文地址:dd linux 命令说明 作者:oychw

dd  linux 命令说明

参考资料

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 的大小,如果没有设定时,预设是 512 bytes

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 root root 1746 Aug 25 14:16 /etc/passwd

-rw-r--r--  1 root root 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=512 count=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/file of=/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 comma separated 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 at start of output

 

       skip=BLOCKS

              skip BLOCKS ibs-sized blocks at start of input

 

       --help display this help and exit

 

       --version

              output version information and exit

 

       BLOCKS  and BYTES may be followed by the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K 1024,

       MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.  Each KEYWORD may be:

 

       ascii  from EBCDIC to ASCII

 

       ebcdic from ASCII to EBCDIC

 

       ibm    from ASCII to alternated EBCDIC

 

       block  pad newline-terminated records with spaces to cbs-size

 

       unblock

              replace trailing spaces in cbs-size records with newline

 

       lcase  change upper case to lower case

 

       notrunc

              do not truncate the output file

 

       ucase  change lower case to upper case

 

       swab   swap every pair of input bytes

 

       noerror

              continue after read errors

 

       sync   pad every input block with NULs to ibs-size; when used

 

              with block or unblock, pad with spaces rather than NULs

 

       Note that sending a SIGUSR1 signal to a running ‘dd’ process makes it print to standard error the number of records

       read and written so far, then to resume copying.

 

              $ dd if=/dev/zero of=/dev/null& pid=$!

              $ kill -USR1 $pid; sleep 1; kill $pid

 

              10899206+0 records in 10899206+0 records out

 

AUTHOR

       Written by Paul Rubin, David MacKenzie, and Stuart Kemp.

 

REPORTING BUGS

       Report bugs to .

 

COPYRIGHT

       Copyright © 2004 Free Software Foundation, Inc.

       This  is  free software; see the source for copying conditions.  There is NO warranty; not even 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 comma separated 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 at start of output

 

       skip=BLOCKS

              skip BLOCKS ibs-sized blocks at start of input

 

       --help display this help and exit

 

       --version

              output version information and exit

 

       BLOCKS  and BYTES may be followed by the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K 1024,

       MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.  Each KEYWORD may be:

 

       ascii  from EBCDIC to ASCII

 

       ebcdic from ASCII to EBCDIC

 

       ibm    from ASCII to alternated EBCDIC

 

       block  pad newline-terminated records with spaces to cbs-size

 

       unblock

              replace trailing spaces in cbs-size records with newline

 

       lcase  change upper case to lower case

 

       notrunc

              do not truncate the output file

 

       ucase  change lower case to upper case

 

       swab   swap every pair of input bytes

 

       noerror

              continue after read errors

 

       sync   pad every input block with NULs to ibs-size; when used

 

              with block or unblock, pad with spaces rather than NULs

 

       Note that sending a SIGUSR1 signal to a running ‘dd’ process makes it print to standard error the number of records

       read and written so far, then to resume copying.

 

              $ dd if=/dev/zero of=/dev/null& pid=$!

              $ kill -USR1 $pid; sleep 1; kill $pid

 

              10899206+0 records in 10899206+0 records out

 

AUTHOR

       Written by Paul Rubin, David MacKenzie, and Stuart Kemp.

 

REPORTING BUGS

       Report bugs to .

 

COPYRIGHT

       Copyright © 2004 Free Software Foundation, Inc.

       This  is  free software; see the source for copying conditions.  There is NO warranty; not even 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  

阅读(737) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册