设为首页 加入收藏

TOP

Linux之dd命令(一)
2014-11-24 07:26:14 来源: 作者: 【 】 浏览:2
Tags:Linux 命令

在安装文件系统时用到了dd命令,对它不是很熟悉,就查了下它的用法,和大家share下


一.dd命令


1.我们先在终端输入命令: man dd,看以下官方的解释 :
NAME
dd - convert and copy a file
SYNOPSIS
dd [OPERAND]...
dd OPTION
DESCRIPTION
Copy a file, converting and formatting according to the operands.
bs=BYTES
read and write BYTES bytes at a time (also see ibs=,obs=)
cbs=BYTES
convert BYTES bytes at a time
conv=CONVS
convert the file as per the comma separated symbol list
count=BLOCKS
copy only BLOCKS input blocks
ibs=BYTES
read BYTES bytes at a time (default: 512)
if=FILE
read from FILE instead of stdin
iflag=FLAGS
read as per the comma separated symbol list
obs=BYTES
write BYTES bytes at a time (default: 512)
of=FILE
write to FILE instead of stdout
oflag=FLAGS
write as per the comma separated symbol list
seek=BLOCKS
skip BLOCKS obs-sized blocks at start of output
skip=BLOCKS
skip BLOCKS ibs-sized blocks at start of input
status=noxfer
suppress transfer statistics
BLOCKS and BYTES may be followed by the following multiplicative suf‐
fixes: c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M
=1024*1024, xM =M GB =1000*1000*1000, G =1024*1024*1024, and so on for
T, P, E, Z, Y.
Each CONV symbol may be:
ascii from EBCDIC to ASCII
ebcdic from ASCII to EBCDIC
ibm from ASCII to alternate 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
nocreat
do not create the output file
excl fail if the output file already exists
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
fdatasync
physically write output file data before finishing
fsync likewise, but also write metadata



Tiger-John说明:


dd的作用是用指定大小的块拷贝一个文件,并在拷贝 的同时进行指定的转换。
1. 命令简介
dd 的主要选项:
指定数字的地方若以下列字符结尾乘以相应的数字:
b=512, c=1, k=1024, w=2, xm=number m
if=file
输入文件名,缺省为标准输入。
of=file
输出文件名,缺省为标准输出。
ibs=bytes
一次读入 bytes 个字节(即一个块大小为 bytes 个字节)。
obs=bytes
一次写 bytes 个字节(即一个块大小为 bytes 个字节)。
bs=bytes
同时设置读写块的大小为 bytes ,可代替 ibs 和 obs 。
cbs=bytes
一次转换 bytes 个字节,即转换缓冲区大小。
skip=blocks
从输入文件开头跳过 blocks 个块后再开始复制。
seek=blocks
从输出文件开头跳过 blocks 个块后再开始复制。(通常只有当输出文件是磁盘或磁带时才有效)。
count=blocks
仅拷贝 blocks 个块,块大小等于 ibs 指定的字节数。
conv=conversion[,conversion...]
用指定的参数转换文件。
转换参数:
ascii 转换 EBCDIC 为 ASCII。
ebcdic 转换 ASCII 为 EBCDIC。
ibm 转换 ASCII 为 alternate EBCDIC.
block 把每一行转换为长度为 cbs 的记录,不足部分用空格填充。
unblock 使每一行的长度都为 cbs ,不足部分用空格填充。
lcase 把大写字符转换为小写字符。
ucase 把小写字符转换为大写字符。
swab 交换输入的每对字节。
noerror 出错时不停止。
notrunc 不截短输出文件。
sync 把每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐。
二.实例分析
1.数据备份与恢复
1>整盘数据备份与恢复
a.备份
将本地的/dev/hdx整盘备份到/dev/hdy :dd if=/dev/hdx of=/dev/hdy
将/dev/hdx全盘数据备份到指定路径的image文件:dd if=/dev/hdx of=/path/to/image
备份/dev/hdx全盘数据,并利用gzip工具进行压缩,保存到指定路径:dd if=/dev/hdx | gzip
>/path/to/image.gz
b.恢复
将备份文件恢复到

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux之编写用户层程序 下一篇编译和使用独立于Linux系统之外的..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)