微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

dd命令的用法

脚本会根据剩余空间的大小来计算一个参数,剩余空间很多时,参数值为A;剩余空间较少时,参数值为剩余空间大小的函数;剩余空间有1G时,总是值A;为了验证参数值为剩余空间大小的函数的情况,需要使获得的剩余空间的值小一些,此时,我们可以使用dd命令来创建一个大小为9000M的空白文件,从而使得剩余空间为1024M这样,然后继续测试。

命令使用示例:

[root@db22 ~]# df -m /home
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/sda3 18043 13072 4055 77% /
[root@db22 ~]# dd if=/dev/zero of=/tmp/holdspace.fil bs=1M count=3000
3000+0 records in
3000+0 records out
3145728000 bytes (3.1 GB) copied,8.92085 s,353 MB/s
[root@db22 ~]# df -m /home
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/sda3 18043 16072 1055 94% /

上面的示例命令可以看到可用空间从4055M变成了1055M,是因为我们创建了一个3000M的空白文件holdspace.fil。
参数说明:
- if:[input file]输入文件
- of:[output file] 输出文件
- bs:[bytes]字节
- count:数量

通过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=)
              每一次读写BYTES个字节

       cbs=BYTES
              convert BYTES bytes at a time
              每一次转换BYTES个字节

       conv=CONVS
              convert the file as per the comma separated symbol list

       count=BLOCKS
              copy only BLOCKS input blocks
              只拷贝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 suffixes: 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
       ...  ...

原文地址:https://www.jb51.cc/bash/390027.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐