Generating blank files in bulk
Scripts must be tested before they are used on a live system. We may need to generate thousands of files to confirm that there are no memory leaks or processes left hanging. This recipe shows how to generate blank files.
Getting ready
The touch
command creates blank files or modifies the timestamp of existing files.
How to do it...
To generate blank files in bulk, follow these steps:
- Invoking the touch command with a non-existent filename creates an empty file:
$ touch filename
- Generate bulk files with a different name pattern:
for name in {1..100}.txt do touch $name done
In the preceding code, {1..100}
will be expanded to 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 exists, the touch
command changes all timestamps associated with the file to the current time. These options define a subset of timestamps to be...