How can I create multiple files within the same directory/sub directory using one command in the terminal?
I know its possible with
touch ./path/to/the/directory/file1.txt ./path/to/the/directory/file2.txt
but looking to see if I can skip entering the fullpath for every file.
I thought touch ./path/to/the/directory/{file1.txt file2.txt} would do the trick, but seems no.
Yes, you can create multiple files within the same directory/sub-directory using one command in the terminal.
we can use touch command and {} wildcard to create multiple files in a single command. Here's an example command,
An example command that does exactly what you want:
touch ./path/to/the/directory/file{1..3}.txt
This command creates file1.txt, file2.txt and file3.txt files inside the sub-directory.
Creating multiple files having completely different names:
touch ./path/to/the/directory/{readme,utils}.txt
This command creates readme.txt, utils.txt files inside the sub-directory.
Creating multiple files having different file extensions:
touch ./path/to/the/directory/{index.html,style.css}
This command creates index.html, style.css files inside the sub-directory.
PS: Above commands are using brace expansion. A brace expansion is contained between a pair of braces “{}”. It can be a list of comma-separated items or a range specifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With