使用 shell 中的内容创建多个文件 [英] Creating multiple files with content from shell

查看:55
本文介绍了使用 shell 中的内容创建多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本新手.如何编写代码来创建多个文件(a.txt、b.txt、...、z.txt)?

New to scripting. How can I write code to create multiple files (a.txt, b.txt, ... , z.txt)?

谢谢.

推荐答案

一个命令创建 26 个空文件:

One command to create 26 empty files:

touch {a..z}.txt

或 152:

touch {{a..z},{A..Z},{0..99}}.txt

一个小循环来创建 152 个包含一些内容的文件:

A small loop to create 152 files with some contents:

for f in {a..z} {A..Z} {0..99}
do
    echo hello > "$f.txt"
done

您可以使用前导零来编号文件:

You can do numbered files with leading zeros:

for i in {0..100}
do
    echo hello > "File$(printf "%03d" "$i").txt"
done

或者,在 Bash 4 中:

or, in Bash 4:

for i in {000..100}
do
    echo hello > "File${i}.txt"
done

这篇关于使用 shell 中的内容创建多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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