Tuesday, November 2, 2021

[SOLVED] How can I create 1000 files that I can use to test a script?

Issue

I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me?


Solution

for i in {0001..1000}
do
  echo "some text" > "file_${i}.txt"
done

or if you want to use Python <2.6

for x in range(1000):
    open("file%03d.txt" % x,"w").write("some text")


Answered By - ghostdog74