AI Hints
Home›Linux Tutorial›Making Folders and Files
Linux · Lesson 22 of 120

mkdir: Making Folders

Creating directories.

⏱ 2 min read▶ Video at 26:16🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

So far we've only looked at folders that already existed. Now let's make our own. The command is MK dir, short for make directory.

mkdir: Making Folders
From the video: mkdir: Making Folders
  • Time to make our own
  • mkdir
  • Make directory

Make a folder

MK dir projects creates a new folder called projects, in the current folder. It prints nothing. In Linux, no news is good news. If a command succeeds quietly, that's normal. LS shows the new folder is there.

Terminal
mkdir projects
ls
Documents  Downloads  Music  Pictures  notes.txt  projects  todo.txt

Several at once

You can make several folders in one go, by listing their names. Here we make three folders, for photos, music, and videos, inside a new folder called backup. But wait. The backup folder doesn't exist yet, so MK dir complains.

Terminal
mkdir backup/photos backup/music backup/videos
mkdir: cannot create directory ‘backup/photos’: No such file or directory
mkdir: cannot create directory ‘backup/music’: No such file or directory
mkdir: cannot create directory ‘backup/videos’: No such file or directory

Parents too, with dash P

Dash P fixes it. It means, make the parent folders too, if they're missing. Now the whole path is created, in one command. Tree draws the folders as a picture, which makes it easy to check.

Terminal
mkdir -p backup/photos backup/music backup/videos
tree backup
backup
├── music
├── photos
└── videos

4 directories, 0 files

Summary

MK dir makes a folder, you can give it several names, and dash P creates missing parent folders too. Next, making empty files.

Key takeaways
  • mkdir <name>
  • Several names at once
  • -p makes parents
Next up: touch: Making Files — empty files and timestamps