← Home

Create Multiple Files at Once with Brace Expansion

Did you know that you can create multiple files with the same name but different extensions all at once using the CLI? Bash/Zsh/Fish etc. have Brace Expansion. So, you can do something like this:

$ echo hi{Ali,Friend,Buddy}hi
> hiAlihi hiFriendhi hiBuddyhi

In this case we're echo-ing (printing) out the text before and after the braces three times, once fo reach of the items in the braces.

This is pretty handy when it comes to making files:

$ touch Button{.js,.css,.stories.js,.test.js}

This also works with number ranges, so if you wanted to create 30 files you could do:

$ touch my-file-{1..30}.txt

I use this all the time when I'm working on React apps.

Be the first to know about my posts!

Share this post with a friend!

LinkedIn
Reddit