Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

mkdir

Create new folders (directories), also with all missing parent folders.

Level
RHCSA exam
Group
Files and folders
Needs root
No
Package
coreutils

What it does

mkdir NAME creates a folder. With -p it also creates every missing folder in the path, and gives no error when the folder already exists, which makes it safe in scripts.

New folders get the permissions 777 minus your umask (usually 755). With -m you choose the permissions at once.

How to write it

mkdir [OPTION]... DIRECTORY...

Options 7

Most used

-p, --parents
Make the parent folders as needed; no error if the folder exists.
-m, --mode=mode
Set the permissions of the new folder, like 750 or u=rwx,g=rx.
-v, --verbose
Print a line for each folder made.
-Z
Set the default SELinux context for the new folder.
--context[=<ctx>]
Like -Z, or set this exact SELinux context.
--help
Show help.
--version
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Make one folder

    mkdir reports

    In the current folder.

  2. 2Make a whole path at once

    mkdir -p /srv/app/releases/2026-10

    Every missing folder is made. No error if it exists.

  3. 3Make several folders with braces

    mkdir -p /data/{web,db,backup}/{logs,tmp}

    Six folders in one command.

  4. 4Make a private folder

    mkdir -m 700 ~/secrets

    Only you can enter it. No separate chmod needed.

  5. 5Make a shared folder for a team

    mkdir -m 2770 /srv/shared
    chgrp devs /srv/shared

    The 2 sets SGID: new files get the group devs.

  6. 6Show what is made

    mkdir -pv /tmp/a/b/c
    mkdir: created directory '/tmp/a'
    mkdir: created directory '/tmp/a/b'
    mkdir: created directory '/tmp/a/b/c'

    Good in logs of scripts.

  7. 7Make a folder with the right SELinux label for a web site

    mkdir -Z /var/www/shop
    ls -dZ /var/www/shop

    The folder gets the default label of its place (httpd_sys_content_t).

  8. 8Make a dated backup folder

    mkdir -p /backup/$(date +%F)

    One folder per day, like /backup/2026-10-25.

  9. 9Make a folder only if it does not exist (script)

    [ -d /var/lib/myapp ] || mkdir -p /var/lib/myapp

    With -p the test is not even needed; it shows the idea.

  10. 10Make a mount point for a new disk

    mkdir -p /mnt/data

    A mount point is just an empty folder.

  11. 11Make the folders of a project from a list

    xargs -a dirs.txt mkdir -p

    One folder name per line in dirs.txt.

Watch out

  • Without -p, a missing parent gives "No such file or directory".
  • -m only applies to the last folder; parents made by -p get the normal permissions.

Tips to remember

  • mkdir -p = safe in scripts.
  • {a,b,c} = many folders at once.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man mkdir