CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / File & Directory Management / mkdir

mkdir

Create directories

Beginneressentialfilesystemscripting

mkdir creates directories. Its -p option creates every missing parent and doesn't complain if the directory already exists, which makes it safe to run again and again in scripts, Dockerfiles and provisioning.

Syntaxmkdir [OPTION]... DIRECTORY...

Watch it run

You are setting up the folder layout for a new service on a fresh server.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 5
mkdir releases

Creates one directory in the current directory. Silence means success.

Anatomy of a command

$
commandmkdir

Make directories.

How it works

mkdir calls the mkdir() system call for each argument. The kernel allocates a new inode of type directory, adds its name to the parent directory, and creates the two entries every directory has: . (itself) and .. (the parent). That's why a new directory has a link count of 2 and why its parent's link count goes up by one. The mode is 0777 minus your umask (typically 022, giving 755) unless -m sets it; note that -m applies only to the last directory, while parents made by -p get the umask default. Without -p, mkdir fails if the parent is missing or the name exists. With -p it creates each missing component in order and treats an existing directory as success, so the command is idempotent. You need write and execute permission on the parent directory.

Options you'll actually use

-pCreate missing parents; no error if it already exists
-m MODESet permissions on the new directory (e.g. 700, 2775)
-vPrint a line for each directory created
{a,b,c}Shell brace expansion: several directories in one go
-ZSet the default SELinux context on the new directory

Common mistakes

mkdir /data/app/logs in a provisioning script

Fails if /data/app doesn't exist yet and fails on re-runs because it already exists.

mkdir -p /data/app/logs
mkdir dir && chmod 700 dir for secrets

For a brief moment the directory exists with the default 775/755 mode.

mkdir -m 700 dir (or set umask 077 first)
mkdir -p -m 700 a/b/c expecting a and b to be 700 too

-m applies only to the final directory; parents get the normal umask mode.

mkdir -p a/b/c && chmod 700 a a/b a/b/c (or set umask 077 in a subshell)
mkdir {dev, prod}

The space breaks brace expansion; you get directories named '{dev,' and 'prod}'.

mkdir {dev,prod}

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Create ~/projects/api/{src,tests,docs} in one command, even though ~/projects/api doesn't exist yet.

  2. 2

    Create a private directory ~/vault that only you can enter, set at creation time. Verify the mode.

  3. 3

    Create a directory named with today's date under ~/backups, e.g. ~/backups/2026-10-29.

Related commands

rmdirRemove empty directoriestouchCreate empty files or update timestampschmodChange file permissionsumaskSet default permissions for new files
PreviousrmNextrmdir
Linux / File & Directory Management / mkdir

mkdir

Create directories

Beginneressentialfilesystemscripting

mkdir creates directories. Its -p option creates every missing parent and doesn't complain if the directory already exists, which makes it safe to run again and again in scripts, Dockerfiles and provisioning.

Syntaxmkdir [OPTION]... DIRECTORY...

Watch it run

You are setting up the folder layout for a new service on a fresh server.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 5
mkdir releases

Creates one directory in the current directory. Silence means success.

Anatomy of a command

$
commandmkdir

Make directories.

How it works

mkdir calls the mkdir() system call for each argument. The kernel allocates a new inode of type directory, adds its name to the parent directory, and creates the two entries every directory has: . (itself) and .. (the parent). That's why a new directory has a link count of 2 and why its parent's link count goes up by one. The mode is 0777 minus your umask (typically 022, giving 755) unless -m sets it; note that -m applies only to the last directory, while parents made by -p get the umask default. Without -p, mkdir fails if the parent is missing or the name exists. With -p it creates each missing component in order and treats an existing directory as success, so the command is idempotent. You need write and execute permission on the parent directory.

Options you'll actually use

-pCreate missing parents; no error if it already exists
-m MODESet permissions on the new directory (e.g. 700, 2775)
-vPrint a line for each directory created
{a,b,c}Shell brace expansion: several directories in one go
-ZSet the default SELinux context on the new directory

Common mistakes

mkdir /data/app/logs in a provisioning script

Fails if /data/app doesn't exist yet and fails on re-runs because it already exists.

mkdir -p /data/app/logs
mkdir dir && chmod 700 dir for secrets

For a brief moment the directory exists with the default 775/755 mode.

mkdir -m 700 dir (or set umask 077 first)
mkdir -p -m 700 a/b/c expecting a and b to be 700 too

-m applies only to the final directory; parents get the normal umask mode.

mkdir -p a/b/c && chmod 700 a a/b a/b/c (or set umask 077 in a subshell)
mkdir {dev, prod}

The space breaks brace expansion; you get directories named '{dev,' and 'prod}'.

mkdir {dev,prod}

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Create ~/projects/api/{src,tests,docs} in one command, even though ~/projects/api doesn't exist yet.

  2. 2

    Create a private directory ~/vault that only you can enter, set at creation time. Verify the mode.

  3. 3

    Create a directory named with today's date under ~/backups, e.g. ~/backups/2026-10-29.

Related commands

rmdirRemove empty directoriestouchCreate empty files or update timestampschmodChange file permissionsumaskSet default permissions for new files
PreviousrmNextrmdir