# Making Folders and Files: mkdir and touch

mkdir makes folders, several at once or a whole path of them with -p, and touch makes an empty file, so one line sets up a tidy place for your files.

Novice · Unix · Linux · Updated November 10, 2026

## After this lesson you can

- Make folders with mkdir, and a whole path of folders at once with mkdir -p
- Make an empty file with touch

## Key takeaways

- mkdir and a name makes a folder in the folder you're in. Give it several names, and it makes one folder for each.
- mkdir -p makes a whole path at once, every missing folder on the way included, and says nothing if the folder is already there.
- touch and a name makes an empty file. On a file that already exists, it only updates the date it last changed.
- A name with spaces needs quotes, or mkdir and touch make one thing for each word.

A new school term starts on Monday. You want a folder for each class, and inside each one a folder for notes and one for homework. Meanwhile your Downloads folder is a pile of summer photos, a lease, receipts and a couple of songs, all waiting for folders to be sorted into. In a file manager, every folder is a right-click, *New Folder*, a name and Enter: a dozen folders is a dozen rounds of that. In the terminal, one line can make them all.

## mkdir: make a folder

`mkdir` is short for *make directory*, and *directory* is the terminal's word for a folder. Give it a name, and it makes that folder. Start this chapter's practice folder, a made-up Downloads folder, and go into it:

```bash
mkdir ~/terminal-practice/downloads
cd ~/terminal-practice/downloads
ls
```

`ls` prints nothing, because the new folder is empty. Give `mkdir` several names, and it makes one folder for each:

```bash
mkdir photos music documents
ls
```

```text
documents  music  photos
```

Ask for a folder that's already there, and `mkdir` stops with an error and changes nothing:

```bash
mkdir photos
```

```text
mkdir: photos: File exists
```

These lessons were run on Ubuntu. On a Mac and on other Linux systems, error messages are worded a little differently, but they mean the same thing. One real difference: a Mac ignores capital letters in names, so there `mkdir Photos` fails too, because `Photos` and `photos` are the same folder. On Linux they're two different folders.

## touch: make an empty file

`touch` makes an empty file. Its name comes from what it does to a file that's already there: it touches it, updating the date it last changed, and leaves what's inside alone. Given a name that isn't there yet, it makes a new, empty file. Fill the practice folder with the mess this chapter sorts out:

```bash
touch IMG_2041.jpg IMG_2042.jpg IMG_2043.jpg IMG_2051.jpg beach-day.png
touch boarding-pass.pdf lease.pdf resume.docx road-trip-mix.mp3 rainy-day.mp3
touch receipt-2026-01.pdf receipt-2026-02.pdf receipt-2026-05.pdf receipt-2026-11.pdf
ls
```

```text
IMG_2041.jpg   boarding-pass.pdf  rainy-day.mp3        resume.docx
IMG_2042.jpg   documents          receipt-2026-01.pdf  road-trip-mix.mp3
IMG_2043.jpg   lease.pdf          receipt-2026-02.pdf
IMG_2051.jpg   music              receipt-2026-05.pdf
beach-day.png  photos             receipt-2026-11.pdf
```

Fourteen files and three folders. The files are stand-ins: a real photo has a picture inside, and these have only a name. `ls -l` shows the size, 0 bytes:

```bash
ls -l lease.pdf
```

```text
-rw-r--r-- 1 sam sam 0 Nov  9 04:03 lease.pdf
```

Your date will be today's. People use `touch` for a file they'll fill in later, such as an empty `notes.txt` for a new class, or for a file a program expects to find.

Both commands follow the rule from *The Shape of a Command*: spaces separate arguments. `mkdir lab reports` makes two folders, `lab` and `reports`; `mkdir "lab reports"` makes one.

## mkdir -p: a whole path at once

Back to the school term. Go up to your practice folder and make a folder for biology, inside `fall-2026`, inside `school`, though neither of those exists yet:

```bash
cd ~/terminal-practice
mkdir school/fall-2026/biology
```

```text
mkdir: No such file or directory
```

`mkdir` makes only the last folder of a path, and it can't put `biology` inside a `fall-2026` that isn't there. (On other systems, this message also names the path.) Add `-p`, for *parents*, the folders a folder sits inside, and `mkdir` makes every missing folder on the way:

```bash
mkdir -p school/fall-2026/biology
ls school
ls school/fall-2026
```

```text
fall-2026
biology
```

`-p` has a second job: when the folder is already there, it says nothing and carries on. That makes `mkdir -p` safe to run twice, which is why the setup lines in this course use it. Add the other classes the same way:

```bash
mkdir -p school/fall-2026/history school/fall-2026/math
ls school/fall-2026
```

```text
biology  history  math
```

Typing `school/fall-2026/` for every class gets old fast. *Brace Expansion: Twelve Folders in One Line* shows how to write it once.

## Try it in the terminal

[Terminal Quest: Moving Day, goal 2](https://www.ask-codey.com/games/terminal-quest/new-place/bash/step): played right on the lesson page.

You've moved into a new apartment, and the movers left your books in the hallway. Give them somewhere to go: make a bookshelf, a new folder, in the living room.

## Check yourself

2 questions to try on the lesson page.

## So what

A new term, a new project and a new job each start with a set of folders. `mkdir -p` makes them in one line, and `touch` adds the empty files you'll fill in later.

## Key terms

- [mkdir](https://www.ask-codey.com/glossary/mkdir)
- [touch](https://www.ask-codey.com/glossary/touch)
- [Directory](https://www.ask-codey.com/glossary/directory)
- [File Path](https://www.ask-codey.com/glossary/file-path)

## Cheat sheets

- [Making Folders and Files: mkdir and touch](https://www.ask-codey.com/cheat-sheets/bash-making-folders-and-files-cheat-sheet)

## Related

- [Copy, Move and Rename: cp and mv](https://www.ask-codey.com/lessons/bash-copy-move-rename)
- [Brace Expansion: Twelve Folders in One Line](https://www.ask-codey.com/lessons/bash-brace-expansion)

Source: https://www.ask-codey.com/lessons/bash-making-folders-and-files
