Do you know about the obscure Linux command ‘seq’????? It is actually quite cool.
seq ‘prints’ (sends to standard output) a sequence of numbers. By itself it does nothing, but with a few parameters it functions nicely.
greg@workstation:~$ seq 10
greg@workstation:~$ seq 3 9
greg@workstation:~$ seq 10 10 110
But why would you want to do this?
To sequentially number files that don’t exist yet using touch, for example!
seq has c-like format capabilities. For those of you who don’t know c, this means that seq understands certain wildcard like tokens that are used to format stuff.
Let’s say we want a sequence of files called “harvey” numbered from 01 to 10. The format for that would be %02g which can be put in the middle of a double-quoted string. So the string “harvey%02g” is a template. The command:
seq -f "harvey%02g" 10
will produce a sequence of ten strings each starting with harvey and ending with a number:
To make these words into empty files, you use the “touch” comand. “touch” followed by a legal filename will update the timestamp of the file referred to. But, if there is no file of that name, touch creates it!
So the string of made-up filenames is fed to touch as follows:
touch $(seq -f "harvey%02g" 10)
This one-liner will get you ten harveys!
Oh, the -f flag in seq tells seq to use the formatting codes.