Learn › Linux Foundations › Manipulation
mkdir - a hands-on Linux lab on a real virtual machine.
Make folders on demand with mkdir. It is silent on success, so every drill proves the result with ls. Learn -p to build a whole nested chain (and forgive a folder that already exists), -v for a confirmation line, and -m to set permissions as you create. Plus the three errors mkdir shows and how to fix each.
Type this and press Enter: mkdir project. Watch the screen. Nothing happens. No message, no confirmation, just a fresh prompt sitting there as if you did nothing at all.
But something did happen. A brand new folder called project now exists on the disk, ready to hold files. The command that made it is mkdir, and its silence is not a bug. In Linux, a command that works quietly and only speaks up when something goes wrong is doing exactly what it should. This lesson teaches you to make folders on demand, and to trust that silence.
The black boxes below are a practice terminal: a safe sandbox that checks the one command each step teaches, so you cannot break anything. Because mkdir prints nothing when it works, every drill here follows it with a second command, ls, to prove the folder really appeared. That pattern, do the silent thing then look at the result, is how you work with mkdir for real.
mkdir is short for make directory. A directory is just another word for a folder: a named container that holds files and other folders. mkdir creates one, empty, wherever you tell it to.
That is the whole job. You hand it a name, it makes a folder with that name. It does not fill the folder, move into it, or announce it. It makes the folder and steps back. Everything else in this lesson is a variation on that one idea. You will make folders faster, in bulk, and with specific settings.
mkdir has been part of Unix since the earliest days in the 1970s, and the name has never changed. Folders needed making from the very beginning, so the tool to make them is one of the oldest commands you will ever run. Every Linux, Mac, and server you touch has it, spelled exactly the same way.
Here is the core move, and the habit that comes with it. You run mkdir to make the folder, and because mkdir says nothing, you run a second command to confirm the folder is really there.
That second command is ls -d. Plain ls lists what is inside a folder; the -d flag tells ls to show the folder itself instead of its contents. So ls -d project asks a simple question: does a folder named project exist? If it prints the name back, the answer is yes.
Before you run this, decide what you expect. mkdir will print nothing, and then ls -d project should print the name project. Run both, one after the other:
mkdir project
ls -d project
prompt: student@linuxcamp:~$ mkdir project answer: ls -d project output: project hint: mkdir already ran and said nothing. Now ask ls to show that one folder: ls -d project
The mkdir project line printed nothing at all, which is exactly what success looks like. Then ls -d project printed project, and that single word is your proof: the folder is now on the disk. This is the rhythm of every silent command in Linux. The tool does the work without comment, and you use a second command, here ls, to see the result for yourself. No news really was good news.
Now a real-world problem. You want a folder inside a folder inside a folder, like a/b/c. The slash / separates each level, so a/b/c means folder c inside folder b inside folder a. But plain mkdir a/b/c fails, because mkdir will not build b and c when their parent a does not exist yet.
The -p flag fixes this. -p stands for parents, and it tells mkdir to make every missing folder in the path, the whole chain, in one command. Confirm the result with ls -R, where -R means show the folders inside folders too:
mkdir -p a/b/c
ls -R a
prompt: student@linuxcamp:~$ mkdir -p a/b/c answer: ls -R a output: a: b
a/b: c
a/b/c: hint: The -p already built the whole chain silently. Now walk it with ls -R a
One command built three nested folders. ls -R a then walked the chain and showed each level: inside a there is b, inside a/b there is c, and a/b/c is empty at the bottom. Without -p, that same mkdir a/b/c would have failed on the missing parent. -p is the flag you reach for any time you want a deep path to just exist, without making each folder by hand.
-p has a second useful habit. Normally, asking mkdir to make a folder that already exists is an error. But with -p, mkdir shrugs and stays silent: if the folder is already there, that is fine, nothing to do, no complaint.
This is why scripts lean on -p. It means make sure this folder exists, whether or not it already does. Run mkdir -p project even though project was made earlier, then confirm nothing broke:
mkdir -p project
ls -d project
prompt: student@linuxcamp:~$ mkdir -p project answer: ls -d project output: project hint: -p makes the second mkdir silent even though project already exists. Confirm with ls -d project
No error, and project is still exactly one folder. With -p, re-making an existing folder is a no-op: mkdir sees it is already there and quietly moves on. Try that same mkdir project WITHOUT -p and you would get an error instead, which is the very next thing this lesson shows you.
Sometimes the silence is inconvenient. When you are making many folders in a script, you want a receipt: a line that says yes, I made that one. The -v flag gives you exactly that. -v stands for verbose, which just means print what you did.
With -v, mkdir prints one confirmation line per folder it creates. This is the one time mkdir talks on success. Make a folder called logs and watch it announce itself:
mkdir -v logs
prompt: student@linuxcamp:~$ answer: mkdir -v logs output: mkdir: created directory 'logs' hint: Add the -v flag between mkdir and the folder name: mkdir -v logs
There is the receipt: mkdir: created directory 'logs'. That is the same folder-making you have done all lesson, but now mkdir says so out loud. -v changes nothing about the result on disk; it only adds the message. Reach for it when you want proof in the moment, especially inside a script that makes a stack of folders and you want to watch each one land.
One more flag worth knowing. Every folder has permissions: a setting that controls who can read, enter, and change it. Normally mkdir picks a default. The -m flag lets you set the permissions at creation time, in one step, where -m stands for mode (mode is the technical word for a permission setting).
You write the mode as three digits, like 700, which here means only the owner can use the folder. Make a private folder and read its permissions back with ls -ld, where -l shows the long detailed listing and -d keeps it to the folder itself:
mkdir -m 700 private
ls -ld private
prompt: student@linuxcamp:~$ mkdir -m 700 private answer: ls -ld private output: drwx------ 2 student student 4096 Jul 5 12:00 private hint: mkdir -m already set the mode silently. Read it back with ls -ld private
The leading drwx------ is the proof. That first d means it is a directory. The rwx means the owner can read, write, and enter it, and the six dashes after mean nobody else can. That locked-down setting came from -m 700, applied the instant the folder was made. Without -m you would create the folder first and change its permissions second; -m folds both into one silent command.
mkdir stays silent on success, so when it DOES speak, something went wrong. Here are the three messages you will meet most, what each one means, and what to check first.
mkdir: cannot create directory 'project': File exists means a file or folder with that name is already there, and without -p that counts as an error. Check first: did you already make it? Either pick a new name, or add -p if you just want to be sure it exists.
mkdir: cannot create directory 'a/b/c': No such file or directory means a parent folder in the path is missing, so mkdir has nowhere to put the last folder. Check first: are the folders above it actually there? The fix is almost always -p, which builds the missing parents for you.
mkdir: cannot create directory '/x': Permission denied means you tried to make a folder somewhere you are not allowed, like the top of the system. Check first: are you in a place you own, such as your home folder? Make it there instead, or the folder genuinely needs an administrator.
The most common one is No such file or directory, and it fools beginners because the folder they named is not the problem, its missing PARENT is. When you see it, do not retype the same command harder. Add -p and let mkdir build the whole path.
Scaffolding off. No command is printed this time. You have every piece you need.
You need a folder buried three levels deep, data/2026/reports, but none of those folders exist yet: not data, not 2026, not reports. Make the entire chain with a single command, the one that builds missing parents without complaint.
prompt: student@linuxcamp:~$ answer: mkdir -p data/2026/reports output: hint: A plain mkdir would fail on the missing parents. Use the flag that makes them for you: mkdir -p, then the full path.
That is the everyday move. mkdir -p data/2026/reports built all three folders in order, data, then 2026 inside it, then reports at the bottom, and printed nothing because it succeeded. You recalled -p from memory, which is the exact recall the real machine will ask of you. A plain mkdir would have stopped at the first missing parent; -p is what lets a deep path simply come into being.
You earned this cheat sheet. Every row is a form of mkdir you just ran:
The one habit under all of it: mkdir works in silence, so you follow it with ls (ls -d for one folder, ls -R for a chain, ls -ld for permissions) to see what it made. And when mkdir finally does speak, read the message, because it is telling you what went wrong.
When in doubt, reach for -p. It builds any missing parents and never errors on a folder that already exists, which makes it the safest form to type when you just want a path to be there. Most engineers use mkdir -p far more than plain mkdir.
The practice terminal has shown you the whole of mkdir. It makes folders in silence, -p builds a deep path and forgives one that already exists, -v prints a receipt, and -m sets permissions as it goes. You proved each one with ls, because a silent command is only trustworthy once you look at what it did. Every command here you typed yourself.
The Manipulation module ends with one real Linux machine, the module capstone mission, and that is where you make folders for real. A VM boots just for you, with a live shell and a real disk. It hands you objectives that use exactly what you practiced across this module: making, copying, moving, and linking files and folders. One difference from here: the mission shows no commands. You read the objective, you recall the command, you type it. That recall is what makes it stick.
Finish the other Manipulation lessons, then go build a directory tree on a real machine.
Practice mkdir in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.