日期:2014-05-16  浏览次数:20810 次

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