![Linux Shell Scripting Cookbook(Third Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/161/36701161/b_36701161.jpg)
上QQ阅读APP看书,第一时间看更新
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 modified:
- touch -a: This modifies the access time
- touch -m: This modifies the modification time
Instead of the current time, we can specify the time and date:
$ touch -d "Fri Jun 25 20:50:14 IST 1999" filename
The date string used with -d need not be in this exact format. It will accept many simple date formats. We can omit time from the string and provide only dates such as Jan 20, 2010.