从Shell创建带有内容的多个文件 [英] Creating multiple files with content from shell

查看:144
本文介绍了从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天全站免登陆