Skip to content
zero2vibecodelearn vibe coding
Level 1 · Files, folders, paths 5 min Reviewed by the author · Aug 4, 2026

Making things: mkdir and touch

`mkdir` makes folders, `touch` makes empty files, and `mkdir -p` builds a whole nested path in one go.

Level 1 · 0 / 4 lessons0%

You can move around. Now make something.

mkdir — make a folder

mkdir projects

Silent, as usual, which means it worked. Run ls and projects is there.

Run it a second time and you get an error:

mkdir: cannot create directory 'projects': File exists

That refusal is deliberate. mkdir will not quietly wipe an existing folder to give you a fresh one — you would lose everything inside it. Commands that could destroy your work generally make you say so explicitly.

Quick check

mkdir refuses to create a folder that already exists. Why is that good?

mkdir -p — the whole at once

Say you want projects/hello-world/src, and none of it exists yet. Plain mkdir fails, because it only creates the last step and the earlier ones are missing:

mkdir projects/hello-world/src
mkdir: cannot create directory 'projects/hello-world/src': No such file or directory

The -p flag says “create the parents too”:

mkdir -p projects/hello-world/src

One line, three folders. This is the version you will use most.

Tip

-p has a second, quieter benefit: it does not complain if the folder is already there. That makes it safe to re-run, which is why setup scripts use mkdir -p almost exclusively.

Quick check

Neither a nor a/b exists. Which command creates a/b/c?

touch — make an empty file

touch notes.txt

That creates an empty file. Zero bytes, but real: ls sees it, and you can write into it later.

If the file already exists, touch leaves its contents completely alone. It is safe to run on anything.

Note

touch is named after what it really does on a real system: it updates a file’s “last modified” timestamp, and creating the file when it is missing is a side effect. In practice, “make me an empty file” is what everybody uses it for.

Naming things you will have to type

You will be typing these names for as long as the project lives, so a few habits save real pain:

  • No spaces. my notes.txt needs quotes every single time. my-notes.txt never does.
  • Lowercase. Some systems treat Notes.txt and notes.txt as the same file and some do not. Staying lowercase means never finding out the hard way.
  • Dashes between words. hello-world reads well and types easily.

Quick check

Why avoid spaces in file names you create in the terminal?

Try it

Build a small project skeleton:

  1. mkdir -p projects/hello-world — the folder and its parent in one step.
  2. cd projects/hello-world — go in.
  3. touch notes.txt — create an empty file.
  4. ls — see it.

Four lines, and you have a folder structure with a file in it. Doing that with a mouse would have taken longer.

Check your understanding

Answered 0/3
Mode:

What does the `-p` flag add to `mkdir`?

What does `touch notes.txt` create?

You run `mkdir photos` twice. What happens the second time?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Build projects/hello-world and put an empty notes.txt inside it.

Tab complete · history · Ctrl+L clear · help commands

  • Not done: Create a folder with mkdir
  • Not done: projects/hello-world exists
  • Not done: notes.txt exists inside it

Lesson Q&A

What does the `-p` flag add to `mkdir`?

Without -p, `mkdir a/b/c` fails unless a and a/b already exist. With -p it creates the whole chain.

What does `touch notes.txt` create?

touch makes an empty file. Putting content in it is a separate step, coming in level 2.

You run `mkdir photos` twice. What happens the second time?

mkdir refuses rather than destroying what is there. That refusal is a safety feature, not a problem to work around.

mkdir refuses to create a folder that already exists. Why is that good?

The error is protecting the contents. Overwriting a folder means destroying whatever was in it.

Neither a nor a/b exists. Which command creates a/b/c?

Plain mkdir only creates the final folder and needs the parents to exist. -p builds the whole chain.

Why avoid spaces in file names you create in the terminal?

A space makes the shell see two arguments. Quotes fix it, but a name that never needs quotes is simpler.

Move between lessons with · search with ⌘K