使用 bash 大量创建文件

use*_*510 5 bash shell-script

我一直试图弄清楚这一点,尝试了不同的命令,但仍然无处可去。你能帮我回答这个问题吗?

在您的主目录中,创建一个名为shirts 的子目录。在子目录中,创建 108 个文件名格式为 style.size.color.ext 的文件,其中每个文件包含下表中的值的一种组合。

Style   tee, crew, turtleneck
Size    XXL, XL, L, M, S, XS
Color   red, yellow, blue
Extension   info, inv
Run Code Online (Sandbox Code Playgroud)

这是我使用的最后一个命令。

$ touch shirts/{tee,crew,turtleneck}.{XXL,XL,L,M,S,XS}.{red,yellow,blue}/{info,inv}
Run Code Online (Sandbox Code Playgroud)

Ram*_*esh 9

您的触摸命令存在轻微错误。你原来的命令,

touch shirts/{tee,crew,turtleneck}.{XXL,XL,L,M,S,XS}.{red,yellow,blue}/{info,inv}
Run Code Online (Sandbox Code Playgroud)

最后有一个/再次尝试创建一个目录,由于该目录不存在,您将收到错误消息,

touch: cannot touch `/shirts/turtleneck.XS.blue/inv': No such file or directory
Run Code Online (Sandbox Code Playgroud)

但是,由于您只需要文件,因此需要将原始命令更改为,

touch shirts/{tee,crew,turtleneck}.{XXL,XL,L,M,S,XS}.{red,yellow,blue}.{info,inv}
Run Code Online (Sandbox Code Playgroud)

PS:您需要确保该目录shirts已经存在。否则,您将再次收到相同的错误cannot touch

  • 不客气。如果这解决了问题,请接受答案以解决问题:) (2认同)