Technical skill

Linux command: mkdir

Subject: .../LINUX

Folders are arranged in paths

A directory is a folder that can contain files and other folders. A path names the steps to one of those folders. For example, archive/service means the service folder inside archive. mkdir creates directories at the paths you give it, so it can create one folder or several levels of a folder tree.

A path follows a branching tree of folders to a file inside a child folder.

Folders can contain more folders; a path follows the branches to a chosen place.

Create the folders you need

This command creates two directories in the current working directory:

mkdir -- cache archive

GNU Coreutils uses -- to mark the end of options. That way a path beginning with a hyphen is treated as a path. If a directory already exists, mkdir reports an error unless you use -p and the existing object is a directory. A missing path component or a regular file in the way also causes failure.

When parent folders might not exist yet, -p creates them as needed:

mkdir -p -- "$HOME/archive/service/2026-11"

In "$HOME/...", $HOME stands for the account's home folder. The quotes keep the expanded path as one argument even if the folder's name contains spaces. Existing parent folders are fine, but a file in the path or a folder you cannot traverse still causes an error. A relative path starts from the current working directory, the folder the command runs in, so check that location before using a relative path in a script. An absolute path is easier to locate; any variable used to build it still needs validation. Validate paths supplied by another program before using them to create folders.

Set and inspect permissions

The permissions on a new directory depend on the process's umask and any default access-control list (ACL) on its parent. The umask filters the permissions a program requests. Read permission lets someone list names, write permission lets them change entries, and execute permission lets them enter or search the directory. Access checks apply to every parent folder and may also be affected by system security rules, so the final mode may differ from what the command alone seems to request.

GNU mkdir -m MODE sets permission bits using a symbolic or numeric mode accepted by chmod. It applies to directories named on the command line; when -p creates parent folders, it does not set that mode on those parents. Choose access for the people who need the directory. A broad mode such as 777 gives more access than most data needs.

After creating a directory, check its owner and mode with stat or ls -ld. This inspects the path created above:

ls -ld -- "$HOME/archive/service/2026-11"

If the result is Permission denied, check write and search permission on each parent, the effective user, ACLs, and security controls. If it says File exists, confirm that the existing object is a directory with the intended owner and mode. mkdir -p accepts an existing directory; it does not fix that directory's permissions. It also does not make later setup commands one all-or-nothing operation, so verify the folder before another program relies on it.

Interactive exercises

Materials

Skillsets
Skillset Skyeng Senior Backend Developer preview
image descriptionSkyeng Senior Backend Developer
by Artem Naumenko (slack2)
39 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Skyeng QA Automation Hard Skillset v09.21 preview
image descriptionSkyeng QA Automation Hard Skillset v09.21
by Aleksandra Kulikova
16 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Show more
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful