全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Linux中dd命令使用实例教程

本文主要给大家介绍了关于Linux中dd命令使用的相关内容,分享出来供大家参考学习,下面来看看详细的介绍:

一、Linux dd命令用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。

使用方法:dd [OPERAND]

参数注释:

 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=N   copy only N 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=WHICH WHICH info to suppress outputting to stderr;
     'noxfer' suppresses transfer stats, 'none' suppresses all

CONVS的可选参数

 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
 sparse try to seek rather than write the output for NUL input blocks
 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

FLAGS的可选参数

 append append mode (makes sense only for output; conv=notrunc suggested)
 direct use direct I/O for data
 directory fail unless a directory
 dsync  use synchronized I/O for data
 sync  likewise, but also for metadata
 fullblock accumulate full blocks of input (iflag only)
 nonblock use non-blocking I/O
 noatime do not update access time
 noctty do not assign controlling terminal from file
 nofollow do not follow symlinks
 count_bytes treat 'count=N' as a byte count (iflag only)

注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:

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

二、使用实例

1、将本地的/dev/hdb整盘备份到/dev/hdd

dd if=/dev/hdb of=/dev/hdd

2、将/dev/hdb全盘数据备份到指定路径的image文件

dd if=/dev/hdb of=/root/image

3、备份/dev/hdb全盘数据,并利用gzip工具进行压缩,保存到指定路径

dd if=/dev/hdb | gzip > /root/image.gz

4、把一个文件拆分为3个文件

#文件大小为2.3k
[Oracle@rhel6 ~]$ ll db1_db_links.sql 
-rw-r--r-- 1 oracle oinstall 2344 Nov 21 10:39 db1_db_links.sql
#把这个文件拆成每个文件1k,bs=1k,count=1,使用skip参数指定在输入文件中跳过多少个bs支读取
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd01.sql bs=1k count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 4.5536e-05 s, 22.5 MB/s
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd02.sql bs=1k count=1 skip=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.000146387 s, 7.0 MB/s
[oracle@rhel6 ~]$ dd if=db1_db_links.sql of=dd03.sql bs=1k count=1 skip=2
0+1 records in
0+1 records out
296 bytes (296 B) copied, 0.000204216 s, 1.4 MB/s
#拆分出的文件
[oracle@rhel6 ~]$ ll dd*sql
-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd01.sql
-rw-r--r-- 1 oracle oinstall 1024 May 20 14:58 dd02.sql
-rw-r--r-- 1 oracle oinstall 296 May 20 14:58 dd03.sql

5、把拆分出的文件合并为1个

#合并操作,此时用到seek参数,用于指定在输入文件中跳过的bs数
[oracle@rhel6 ~]$ dd of=1.sql if=dd01.sql 
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.000176 s, 5.8 MB/s
[oracle@rhel6 ~]$ dd of=1.sql if=dd02.sql bs=1k seek=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.000124038 s, 8.3 MB/s
[oracle@rhel6 ~]$ dd of=1.sql if=dd03.sql bs=1k seek=2
0+1 records in
0+1 records out
296 bytes (296 B) copied, 0.00203881 s, 145 kB/s
#与拆分前的文件进行校验
[oracle@rhel6 ~]$ diff 1.sql db1_db_links.sql
[oracle@rhel6 ~]$

6、在输出文件中指定的位置插入数据,而不截断输出文件

需要使用conv=notrunc参数

[oracle@rhel6 ~]$ dd if=2.sql of=1.sql bs=1k seek=1 count=2 conv=notrunc

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。


# linux  # dd命令  # linux中dd命令  # dd命令详解  # linux/OSX中“DD”命令制作ISO镜像操作系统安装U盘的方法  # linux 详解useradd 命令基本用法  # 浅谈Linux中ldconfig和ldd的用法  # DDNS 的工作原理及其在 Linux 上的实现  # 一天一个shell命令 文本操作系列-linux dd使用教程  # linux命令详解之useradd命令使用方法  # linux系统下dd命令的使用方法  # 预防PHPDDOS的发包攻击别人的方法(iis+linux)  # Linux中在不破坏磁盘的情况下使用dd命令  # 可选  # 跳过  # 默认为  # 相关内容  # 并在  # 而不  # 给大家  # 来看看  # 这篇文章  # 谢谢大家  # 多少个  # 数据备份  # 若以  # 文件合并  # 拆成  # 有疑问  # stats  # transfer  # suppresses  # ascii 


相关文章: 建站之星如何实现五合一智能建站与营销推广?  如何在橙子建站上传落地页?操作指南详解  如何通过西部建站助手安装IIS服务器?  香港服务器网站推广:SEO优化与外贸独立站搭建策略  如何选择高效便捷的WAP商城建站系统?  定制建站流程步骤详解:一站式方案设计与开发指南  如何正确下载安装西数主机建站助手?  如何自定义建站之星模板颜色并下载新样式?  建站之星如何通过成品分离优化网站效率?  ,巨量百应是干嘛的?  活动邀请函制作网站有哪些,活动邀请函文案?  如何通过智能用户系统一键生成高效建站方案?  C++时间戳转换成日期时间的步骤和示例代码  阿里云高弹*务器配置方案|支持分布式架构与多节点部署  如何选择服务器才能高效搭建专属网站?  交易网站制作流程,我想开通一个网站,注册一个交易网址,需要那些手续?  建站中国官网:模板定制+SEO优化+建站流程一站式指南  建站主机系统SEO优化与智能配置核心关键词操作指南  在线ppt制作网站有哪些软件,如何把网页的内容做成ppt?  如何快速搭建高效WAP手机网站吸引移动用户?  如何有效防御Web建站篡改攻击?  网站建设制作需要多少钱费用,自己做一个网站要多少钱,模板一般多少钱?  如何高效生成建站之星成品网站源码?  ,怎么在广州志愿者网站注册?  教学论文网站制作软件有哪些,写论文用什么软件 ?  常州自助建站费用包含哪些项目?  如何在宝塔面板中创建新站点?  c++怎么编写动态链接库dll_c++ __declspec(dllexport)导出与调用【方法】  北京制作网站的公司,北京铁路集团官方网站?  建站主机选购指南与交易推荐:核心配置解析  重庆网站制作公司哪家好,重庆中考招生办官方网站?  音乐网站服务器如何优化API响应速度?  建站10G流量真的够用吗?如何应对访问高峰?  如何用虚拟主机快速搭建网站?详细步骤解析  高端建站如何打造兼具美学与转化的品牌官网?  已有域名能否直接搭建网站?  建站之星如何实现PC+手机+微信网站五合一建站?  如何用已有域名快速搭建网站?  香港服务器网站生成指南:免费资源整合与高速稳定配置方案  如何用搬瓦工VPS快速搭建个人网站?  高性能网站服务器配置指南:安全稳定与高效建站核心方案  如何用wdcp快速搭建高效网站?  建站之星后台管理:高效配置与模板优化提升用户体验  中山网站推广排名,中山信息港登录入口?  h5网站制作工具有哪些,h5页面制作工具有哪些?  广东专业制作网站有哪些,广东省能源集团有限公司官网?  如何在服务器上配置二级域名建站?  如何快速辨别茅台真假?关键步骤解析  建站主机如何安装配置?新手必看操作指南  如何通过虚拟主机快速完成网站搭建? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。