我试图让终端在随机目录中制作一堆文件(它在一个循环中),随机名称,随机大小,随机数据。通过随机目录我的意思是他们可以在计算机上的任何地方
也许这个脚本是一个起点
#!/bin/bash
for i in {1..5}
do
# Create random file
#
data=$(od -vAn -N4 -tu4 < /dev/urandom)
random_file=$(mktemp)
echo "$data" > "$random_file"
echo "Created $random_file file, with data=$data"
# Create random directory
#
random_dir=$(mktemp -d)
echo "Created $random_dir directory"
done
输出:
Created /tmp/tmp.Toet7Wn7bz file, with data= 4221696069
Created /tmp/tmp.kc9OLaX84U directory
Created /tmp/tmp.S2OQ8Wh6Iz file, with data= 172066121
Created /tmp/tmp.d1oFQ4DINx directory
Created /tmp/tmp.wGl42vpRLc file, with data= 3188097801
Created /tmp/tmp.xbAhMUFAZi directory
Created /tmp/tmp.4dI5M7amYL file, with data= 1085037810
Created /tmp/tmp.vAMAg39pjK directory
Created /tmp/tmp.AXP6yztDMj file, with data= 2348013838
Created /tmp/tmp.Qc5kyZtmnn directory
它生成5个随机文件,存储随机数和5个随机目录。
这只是一个初步的想法( - >目录和文件没有嵌套等,但我想这应该可以扩展这个初始脚本。