linux下创建任意大小文件 —— dd命令

dd命令可以用来创建任意大小文件,如:

在当前目录下创建一个文件名为file的10M的空文件

dd if=/dev/zero of=./file.txt bs=1M count=10    


下面为一个脚本,可以创建指定数量、大小和名称的文件(蓝色部分为脚本内容)

linux:/mnt/hgfs/vmware-share/dd # cat test.sh
#!/bin/bash

count=0
MAX=10
FileName='file'

while [ ${count} -lt ${MAX} ]
do
        #echo ${count}
        tmp=${FileName}${count}
        #echo ${tmp}
  dd if=/dev/zero of=./${tmp} bs=1M count=10
        ((count++))
done
linux:/mnt/hgfs/vmware-share/dd #

执行结果:

linux:/mnt/hgfs/vmware-share/dd # ll
总用量 51205
drwxrwxrwx  1 root root     4096 2014-03-27 00:18 .
drwxrwxrwx  1 root root     4096 2014-03-26 23:49 ..
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file0
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file1
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file2
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file3
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file4
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file5
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file6
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file7
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file8
-rwxrwxrwx  1 root root 10485760 2014-03-27 00:13 file9
-rwxrwxrwx  1 root root      197 2014-03-27 00:13 test.sh

关于dd命令的更多用法:

http://blog.csdn.net/adaptiver/article/details/6672592

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值