日常进行文件读写IO测试时,经常需要构造大文件,本文记录常见的linux大文件构造命令
本文主要参考链接:mp.weixin.qq.com/s/HDVZZnlz2…
dd
语法
dd if=[source] of=[destination] bs=[block-size] count=[how much block]
# 参数解释
if # 读取字符的原文件
of # 写入的文件
bs # 文件块大小
count # 写入多少块
示例
dd if=/dev/zero of=/Users/xx/testfile1 bs=1m count=10
/dev/zero # 代表空字符设备,上面的命令即是从空字符设备连续读取10M的空字符写入testfile1文件
du -h /Users/xx/testfile1 可以查看文件大小,也是10M
yes | head -c
# yes 命令是循环输出特定的字符
# 结合 head 去中断循环
示例
yes "test file" | head -c 1048576 > testfile2
# head -c 的单位是字节数,1048576 = 1024*1024 即写入1M的数据到testfile2