LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 125|回复: 0

Linux快速生成大量随机大小的小文件

[复制链接]
发表于 2023-12-17 22:18:59 | 显示全部楼层 |阅读模式

Linux快速生成大量随机大小的小文件
# 在当前目录下,生成50W个大小0-8K的随机txt文件
n=500000
size=8
time perl -E '
  $n=shift;
  $max_size=1024 * shift;
  for(1..$n){
    open $f, ">", "$_.txt" or die "open failed: $!";
    print {$f} "0" x int(rand($max_size));
    close $f or die "close failed: $!";
  }
' $n $size

real    0m8.073s
user    0m1.618s
sys     0m6.313s

文章链接: https://www.junmajinlong.com/shell/many_small_files/
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表