How to create multiple directories at once?

QuestionsQuestions4 SkillsProDec, 18 2025
0234

That's a great question! In Linux, the mkdir command is very flexible. You can create multiple directories at once in a few different ways:

1. By listing them with spaces

As I briefly mentioned, the simplest way is to provide multiple folder names separated by spaces:

mkdir folder1 folder2 folder3

For your specific task in this lab, you can do it in one line like this:

mkdir ~/project/digital_garden/notes ~/project/digital_garden/projects ~/project/digital_garden/resources

2. Using "Brace Expansion" (The Pro Way)

Linux shells like Bash have a powerful feature called brace expansion. This allows you to create many directories with a common path very quickly:

mkdir ~/project/digital_garden/{notes,projects,resources}

Note: Make sure there are no spaces inside the curly braces {}!

3. Creating nested directories (The -p flag)

If you want to create a directory and its parent directories at the same time (e.g., creating a/b/c when a doesn't exist yet), use the -p (parents) flag:

mkdir -p ~/project/folder_a/folder_b/folder_c

Give the brace expansion method a try—it's a real time-saver! Let me know if you'd like to dive deeper into any of these.

0 Comments

no data
Be the first to share your comment!