您的位置:首页 > 运维架构 > Linux

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

2014-03-27 00:19 363 查看
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命令的更多用法:

/article/8176978.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: