Create multiple folders at once on the terminal

August 08, 2020
1 min read

Create multiple folders at once on the terminal

I think you are familiar with the problem. You start a new project and to make the structure you should do something like this:

mkdir new-project && cd new-project
mkdir src && cd src

// Create folders
mkdir components
mkdir assets
mkdir configs
mkdir locales
// ...

This is so frustrating! There should be a better solution šŸ¤”

You can use this syntax to create multiple folders in a directory at once. Plain and simple:

mkdir -p new-project/src/{components,assets,configs,locales}

šŸ˜² Just that? Yes, just that. But let's review what happened here:

  • You use -p to create sub-directories and on each level, if it doesn't exist, it makes sure that it will be.
  • Then with {} you pass a comma-separated list of names to create multiple directories beside each other.

Wasn't that bad, hah?