脚本新手。如何编写代码来创建多个文件(a.txt、b.txt、...、z.txt)?
谢谢。
最佳答案
一条命令创建26个空文件:
touch {a..z}.txt
或 152:
touch {{a..z},{A..Z},{0..99}}.txt
创建 152 个包含一些内容的文件的小循环:
for f in {a..z} {A..Z} {0..99}
do
echo hello > "$f.txt"
done
您可以使用前导零对文件进行编号:
for i in {0..100}
do
echo hello > "File$(printf "%03d" "$i").txt"
done
或者,在 Bash 4 中:
for i in {000..100}
do
echo hello > "File${i}.txt"
done
关于bash - 使用 shell 中的内容创建多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4140822/