Linux生成大文件

参数if为输入文件名,of为输出文件名,bs为单次读取和写入的字节数,count为拷贝的次数,因而总文件大小为bs*count


dd if=/dev/zero of=test count=102400 bs=1024
查看内容
od -tc test
如果希望文件有多行信息,可以将if设置为/dev/urandom——提供不为空字符的随机字节数据流。

dd if=/dev/urandom of=test count=1024 bs=1024

fallocate命令

fallocate命令可以为文件预分配物理空间。-l后接空间大小,默认单位为字节。也可后跟k、m、g、t、p、e来指定单位,分别代表KB、MB、GB、TB、PB、EB。

fallocate -l 100m new_file_2

truncate命令

truncate命令可以将文件缩减或扩展为指定大小,使用-s参数设置大小。


truncate -s 100M test

参考链接

https://www.jianshu.com/p/81fc1297a7c4

http://www.skorks.com/2010/03/how-to-quickly-generate-a-large-file-on-the-command-line-with-linux/

https://stackoverflow.com/questions/257844/quickly-create-a-large-file-on-a-linux-system

https://www.deimeke.net/dirk/blog/index.php?/archives/3477-dd-vs.-fallocate-vs.-truncate-....html