mkdir -p & touch

Make folders and files

Lesson 5 of 20 · 7 min · Module 2: Shape your files

Before you can organize work, you need places to put it.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Create folders, including parents
  • Create empty files
  • Pass several names to one command

The idea

mkdir name creates a folder. mkdir -p a/b/c creates the whole chain, including any missing parent folders, and does not complain if they already exist. touch file creates an empty file (or updates the date of an existing one).

mkdir -p course/week1
touch course/week1/plan.txt
ls course/week1

01Without -p, parents must exist

mkdir course/week1 fails if course does not exist yet. mkdir -p creates every missing folder along the way.

mkdir a/b
mkdir -p a/b
Output
mkdir: cannot create directory 'a/b': No such file or directory

02touch makes an empty file

Many tools expect a file to exist before they write to it. touch is the quickest way to create one. Running it again on an existing file only updates its date.

03One command, many names

mkdir and touch both accept several names: touch a.txt b.txt c.txt creates three files at once. Separate names with spaces.

Your turn

Create the folder course/week1/notes inside your home folder with one command. Then create two empty files in course/week1: plan.txt and ideas.txt.

What the checks look for

  • Creates ~/course/week1/notes
  • Creates an empty plan.txt
  • Creates an empty ideas.txt
Try it in the editor →

Take this with you

mkdir -p builds a whole folder path; touch creates empty files.

Go a little further

Create a file whose name contains a space, then list it with ls to see how it appears.

Learn Linux Command Line for free

20 short lessons with real code and instant checks.

See the whole course →