Sometimes you need dummy folder structures populated with random data for testing your various scripts and processes – backups, file transfers, encryption, compression, etc. Every time I need something like this, I end up writing my little script from scratch.

I’ve written many of these little loops that I’ve lost and forgotten. But here’s the final, definitive version. No more, I promise.

This nested loop will create two folder structures populated with up to 12 subfolders each. Every subfolder will contain up to 120 files. Each file will be no more than 256KB in size, containing lines anywhere between 60 and 280 random alphanumeric characters long. So we are talking about 720MB tops. It’s a good random data set for running various tests.

Now, if you’re wondering about the set +/-o history lines, this is to make sure the pids+=($!) doesn’t conflict with your shell history. As you can see, each dir_* is populated via a subshell running in the background. This just greatly speeds things up (at the expense of your CPUs, of course).