Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple files with content from shell

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

Thanks.

like image 587
Kevin Avatar asked Nov 10 '10 02:11

Kevin


1 Answers

One command to create 26 empty files:

touch {a..z}.txt 

or 152:

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

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 

or, in Bash 4:

for i in {000..100} do     echo hello > "File${i}.txt" done 
like image 114
Dennis Williamson Avatar answered Oct 04 '22 10:10

Dennis Williamson