经常有看到VPS、服务器等主机商有提供个例如100MB-fremont.bin、100mb.test等的文件,供用户下载测试网络使用。
本文介绍下如何在Linux,命令行下创建指定大小的文件(这里以创建13MB大小的文件onebox.test为例)。
truncate
truncate -s 13M onebox.test
fallocate
fallocate -l 13000000 onebox.test
dd
dd if=/dev/urandom of=onebox.test bs=13MB count=1
OR
head -c 13MB /dev/urandom > onebox.test
dd if=/dev/zero of=onebox.test bs=13MB count=1
OR
head -c 13MB /dev/zero > onebox.test
额外
13MB=1310001000字节;如果想要1310241024,则替换MB为M,示例:
dd if=/dev/urandom of=onebox.test bs=13M count=1
head -c 13M /dev/zero > onebox.test
命令fallocate只支持字节(bytes)单位,如果想创建1310241024大小的文件,则1310241024=13631488:
fallocate -l 13631488 onebox.test