mkdirCreate directories
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.
mkdir [OPTION]... DIRECTORY...You are setting up the folder layout for a new service on a fresh server.
mkdirMake directories.
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.
-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 directorymkdir /data/app/logs in a provisioning scriptFails if /data/app doesn't exist yet and fails on re-runs because it already exists.
mkdir -p /data/app/logsmkdir dir && chmod 700 dir for secretsFor 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}Try these on a Linux machine of your own. Each task has a hint and a solution.
Create ~/projects/api/{src,tests,docs} in one command, even though ~/projects/api doesn't exist yet.
Create a private directory ~/vault that only you can enter, set at creation time. Verify the mode.
Create a directory named with today's date under ~/backups, e.g. ~/backups/2026-10-29.
mkdirCreate directories
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.
mkdir [OPTION]... DIRECTORY...You are setting up the folder layout for a new service on a fresh server.
mkdirMake directories.
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.
-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 directorymkdir /data/app/logs in a provisioning scriptFails if /data/app doesn't exist yet and fails on re-runs because it already exists.
mkdir -p /data/app/logsmkdir dir && chmod 700 dir for secretsFor 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}Try these on a Linux machine of your own. Each task has a hint and a solution.
Create ~/projects/api/{src,tests,docs} in one command, even though ~/projects/api doesn't exist yet.
Create a private directory ~/vault that only you can enter, set at creation time. Verify the mode.
Create a directory named with today's date under ~/backups, e.g. ~/backups/2026-10-29.