Reputation: 23737
How can I create more than one file within a folder with the touch
command? More specifically, lets say, I want to create three new files - local.js
, facebook.js
and twitter.js
in a folder that has path config/strategies/
. This is what I am currently doing:
touch config/strategies/local.js config/strategies/facebook.js config/strategies/twitter.js
.
What I want to know is if there is a shorter way to do this.
Thank you in advance.
Upvotes: 2
Views: 41
Reputation: 113834
You can use bash's brace expansion:
$ touch config/strategies/{local,facebook,twitter}.js
$ ls config/strategies/
facebook.js local.js twitter.js
Brace expansion comes in two forms. The first uses commas between items in the list:
$ echo 1{b,c}2
1b2 1c2
The second uses ..
and causes a sequence of words to be created:
$ echo 1{a..f}2
1a2 1b2 1c2 1d2 1e2 1f2
With a sequence, it is also possible to specify an increment:
$ echo 1{a..f..2}2
1a2 1c2 1e2
With 2 specified as the increment, then every other letter between a
and f
is generated by the expansion
Upvotes: 4