Chapter 15: Bash Make Dir (mkdir)

What does mkdir mean?

mkdir = make directory

It creates folders (directories) from the terminal.

Without it you would have to use a file manager → right-click → New Folder → type name → Enter… very slow when doing many folders or deep paths.

1. Simplest way – create one folder

Bash

After this command → you will see the new empty folder.

Check it:

Bash

You should see photos, backup-2026, etc.

2. Create many folders at once (very common)

Bash

Now you have 12 + 5 = 17 folders in one line — super fast!

3. The MOST important option → -p (parents)

This is the one you will use 90% of the time in real scripts/projects.

Bash

But this works perfectly:

Bash

What -p does:

  • Creates all missing parent folders automatically
  • Does NOT give error if the folder already exists (very safe in scripts)
  • Very useful for git repos, docker volumes, laravel/cache folders, python virtualenvs, etc.

Real example most developers use daily:

Bash

This creates:

text

4. See what is happening → -v (verbose)

Bash

You will see output like:

text

Very helpful when you want to confirm everything was created.

5. Set permissions at creation time → -m (mode)

Normally new folders get drwxr-xr-x (755) because of your umask.

But you can force specific permissions:

Bash

Common real uses:

  • 700 → private keys, credentials, personal notes
  • 755 → normal web folders, scripts
  • 775 → shared team folders (group write)

6. Brace expansion tricks (Bash super power)

Create many numbered folders quickly:

Bash

Even better with -p:

Bash

This creates a nice yearly/monthly archive structure.

7. Quick cheat-sheet table

What you want Command example Notes
One normal folder mkdir notes Basic
Many folders mkdir old new temp backup
Deep path (safest way) mkdir -p src/components/Button Most used
See every step mkdir -vp logs/2026/{01,02,03} Debugging
Private folder (only me) mkdir -m 700 .ssh/old-keys Security
Team folder (group write) mkdir -m 775 team-documents Collaboration
Numbered folders mkdir week-{1..10} Reports, logs
Many nested at once mkdir -p app/{controllers,models,views,config} MVC pattern
No error if already exists mkdir -p cache Scripts love this

8. Common real-life examples (copy-paste ready)

  • Laravel project structure
Bash
  • Python project
Bash
  • Daily log folders (today is 2026-02-25)
Bash
  • Exam preparation folders
Bash

9. What if I make mistake?

  • Folder already exists → normal mkdir says: mkdir: cannot create directory ‘xxx’: File exists
  • But with -p → silent (no error) → very safe
  • Want to remove empty folder? → use rmdir foldername (only works if empty)
  • Want to remove folder + everything inside? → rm -r foldername (careful!)

Now you know mkdir like 95% of Linux users.

Practice these 3 right now in your terminal:

Bash

Tell me what you see — or ask: “how to create 100 folders named file-001 to file-100?” or “how to make folders only if I’m in Downloads?” — I’ll show exact commands! 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *