侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux中dd命令使用实例教程

linux  /  管理员 发布于 7年前   460

本文主要给大家介绍了关于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 =MGB =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=11+0 records in1+0 records out1024 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=11+0 records in1+0 records out1024 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=20+1 records in0+1 records out296 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 in2+0 records out1024 bytes (1.0 kB) copied, 0.000176 s, 5.8 MB/s[oracle@rhel6 ~]$ dd of=1.sql if=dd02.sql bs=1k seek=11+0 records in1+0 records out1024 bytes (1.0 kB) copied, 0.000124038 s, 8.3 MB/s[oracle@rhel6 ~]$ dd of=1.sql if=dd03.sql bs=1k seek=20+1 records in0+1 records out296 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中xargs命令的各种使用技巧
    下一条:
    linux中echo命令的用法实例教程
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客