O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating blank files in bulk

Sometimes we many need to generate test cases. We may use programs that operate on 1000s of files. But how are test files generated?

Getting ready

touch is a command that can create blank files or modify the timestamp of files if they already exist. Let's take a look at how to use them.

How to do it...

A blank file with the name filename will be created using the following command:

$ touch filename

Generate bulk files with a different name pattern as follows:

for name in {1..100}.txt
do
touch $name
done

In the above code {1..100} will be expanded as a string "1, 2, 3, 4, 5, 6, 7...100". Instead of {1..100}.txt, we can use various shorthand patterns such as test{1..200}.c, test{a..z}.txt, and so on.

If a file already ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required