Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · file management

mkdir

making room

mkdir creates a directory. By default the parent has to exist already and the name must be free; -p removes both conditions, creating every missing level and staying quiet if the directory is already there — which is why scripts almost always use it.

mkdir -p means "make sure this path exists" — safe to run once or a hundred times.

Creates
Directories
empty ones
Nested paths
-p
parents made as needed
Default mode
755
777 minus the umask of 022
Opposite
rmdir
removes an empty directory

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashcoreutils
$ mkdir -p site/assets/img
$ mkdir site
1mkdir: cannot create directory 'site': File exists
$ ls -ld site
2drwxr-xr-x 3 user user 4096 Sep 30 10:20 site
3$ mkdir -m 700 site/private
$ ls -ld site/private
4drwx------ 2 user user 4096 Sep 30 10:21 site/private
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
Without -p, an existing name is an error

The first command already created site, assets and img in one go and printed nothing. Asking again without -p fails.

2
The mode comes from the umask

A new directory asks for rwxrwxrwx and the umask of 022 removes write for group and others, leaving rwxr-xr-x.

3
-m sets the permissions at creation

The directory never exists with looser permissions, even for a moment — better than mkdir followed by chmod.

4
Only the owner may enter

drwx------ shuts out the group and everyone else entirely.

Switches

A switch changes how the command behaves. These are the ones used day to day; man mkdir lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-p
Parents: create any missing directories along the path, and do not complain if it already exists.
-v
Verbose: print a line for each directory created.
-m MODE
Set the permissions at creation, for example -m 700.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

mkdir -p logs/{app,nginx,db}

Brace expansion: three subdirectories in one command.

mkdir -pv a/b/c

Prints a line for each directory it actually had to create.

mkdir -m 700 ~/.ssh

The mode SSH insists on for its configuration directory.

rmdir empty-dir

Removes a directory only if nothing is inside it — a safe way to tidy up.

In cybersecurity

A directory's permissions decide who can create, rename and delete the files in it — regardless of what the files themselves allow.

Write on a directory is powerful

Anyone with write permission on a directory can delete or replace files in it, even files they cannot read.

Create it private

For anything sensitive use -m 700 at creation. Tightening afterwards leaves a window where it was open.

Shared temp directories

A predictable directory name under /tmp can be created first by another user. Use mktemp -d instead.

Filed under

File management

Read alongside