Alex Rivera | Logout

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

Asked 2010-01-18T09:00:37.857
11

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?

Edit
Report

1 Answer

2

Just take any big file that has more than 1000 bytes (for 1000 files with content). There are lots of them on your computer. Then do (for example):

split -n 1000 /usr/bin/firefox

This is instantly fast.

Or a bigger file:

split -n 10000 /usr/bin/cat

This took only 0.253 seconds for creating 10000 files.

For 100k files:

split -n 100000 /usr/bin/gcc

Only 1.974 seconds for 100k files with about 5 bytes each.

If you only want files with text, look at your /etc directory. Create one million text files with almost random text:

split -n 1000000 /etc/gconf/schemas/gnome-terminal.schemas

20.203 seconds for 1M files with about 2 bytes each. If you divide this big file in only 10k parts it only takes 0.220 seconds and each file has 256 bytes of text.

answered 2013-01-30T01:17:00.297

Your Answer