-
Book Overview & Buying
-
Table Of Contents
Linux Shell Scripting Cookbook, Second Edition - Second Edition
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.
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.
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
doneIn 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 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. However, if we want to specify that only certain stamps are to be modified, we use the following options:
touch -a modifies only the...
Change the font size
Change margin width
Change background colour