在bash中生成虚拟文件 [英] Generate dummy files in bash

查看:81
本文介绍了在bash中生成虚拟文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在bash中生成虚拟文件.内容无关紧要,如果是随机的就可以了,但是所有相同的字节也是可以接受的.

I'd like to generate dummy files in bash. The content doesn't matter, if it was random it would be nice, but all the same byte is also acceptable.

我的第一次尝试是以下命令:

My first attempt was the following command:

rm dummy.zip;
touch dummy.zip;
x=0;
while [ $x -lt 100000 ];
do echo a >> dummy.zip;
  x=`expr $x + 1`;
done;

问题在于其性能不佳.我在Windows上使用GitBash,因此在Linux下可能更快,但脚本显然不是最佳选择.

The problem was its poor performance. I'm using GitBash on Windows, so it might be much faster under Linux but the script is obviously not optimal.

您能建议我一种更快且更好的方法来生成给定大小的虚拟(二进制)文件吗?

Could you suggest me a quicker and nice way to generate dummy (binary) files of given size?

推荐答案

您可以尝试 head 命令:

$ head -c 100000 /dev/urandom >dummy

这篇关于在bash中生成虚拟文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆