Generating blank files in bulk
Sometimes we may need to generate test cases to test programs that operate on thousands of files. Let's discuss how to generate such files in this recipe.
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 preceding 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 astest{1..200}.c
,test{a..z}.txt
, and so on.If a file already exists, the
touch
command changes all timestamps associated with the file to the current time. However, if we want to specify that only certain stamps are to be modified, we use the following options:touch -a
modifies only the...