mkdir Command in Linux: Create Directories

By 

Updated on

5 min read

Creating directories in Linux with the mkdir command

The mkdir command creates new directories (folders) in Linux from the command line. You will use it whenever you need to set up a project layout, organize files, or prepare paths for scripts and configuration.

This guide covers how to use mkdir to create single and multiple directories, build nested directory trees, and set permissions at creation time.

Linux mkdir Command Syntax

The syntax for the mkdir command is as follows:

txt
mkdir [OPTION] DIRECTORY...

The command takes one or more directory names as its arguments.

How to Create a New Directory

To create a directory in Linux, pass the directory’s name as the argument to the mkdir command. For example, to create a new directory newdir, you would run the following command:

Terminal
mkdir newdir

You can verify that the directory was created by listing the contents using the ls command :

Terminal
ls -l
output
drwxrwxr-x 2 username username 4096 Jan 20 03:39 newdir

When you provide only the directory name, without the full path, it is created in the current working directory.

The current working directory is the directory from which you are running the commands. To change the current working directory, use the cd command.

To create a new directory in another location, provide the absolute or relative path to the parent directory. For example, to create a new directory in the /tmp directory, you would type:

Terminal
mkdir /tmp/newdir

If you try to create a directory in a parent directory where the user does not have sufficient permissions, you will receive a Permission denied error:

Terminal
mkdir /root/newdir
output
mkdir: cannot create directory '/root/newdir': Permission denied

The -v (--verbose) option tells mkdir to print a message for each created directory:

Terminal
mkdir -v newdir
output
mkdir: created directory 'newdir'

How to Create Parent Directories

A parent directory is a directory that is above another directory in the directory tree. To create parent directories, use the -p option.

Suppose you want to create a directory /home/linuxize/Music/Rock/Gothic:

Terminal
mkdir /home/linuxize/Music/Rock/Gothic

If any of the parent directories do not exist, you will get an error:

output
mkdir: cannot create directory '/home/linuxize/Music/Rock/Gothic': No such file or directory

Instead of creating the missing parent directories one by one, invoke the mkdir command with the -p option:

Terminal
mkdir -p /home/linuxize/Music/Rock/Gothic

When the -p option is used, the command creates the directory only if it does not already exist.

If you try to create a directory that already exists and the -p option is not provided, mkdir will print File exists error:

Terminal
mkdir newdir
output
mkdir: cannot create directory 'newdir': File exists

How to Set Permissions when Creating a Directory

To create a directory with specific permissions, invoke the mkdir command with the -m (--mode) option. The syntax for assigning permissions is the same as with the chmod command.

In the following example, we are creating a new directory with 700 permissions, which means that only the user who created the directory will be able to access it:

Terminal
mkdir -m 700 newdir

When the -m option is not used, the newly created directories usually have either 775 or 755 permissions, depending on the umask value.

How to Create Multiple Directories

To create multiple directories, specify the directories’ names as the command arguments, separated by spaces:

Terminal
mkdir dir1 dir2 dir3

The mkdir command also allows you to create a complex directory tree with one command:

Terminal
mkdir -p Music/{Jazz/Blues,Folk,Disco,Rock/{Gothic,Punk,Progressive},Classical/Baroque/Early}

The command above creates the following directory tree:

output
Music/
|-- Classical
|   `-- Baroque
|       `-- Early
|-- Disco
|-- Folk
|-- Jazz
|   `-- Blues
`-- Rock
    |-- Gothic
    |-- Progressive
    `-- Punk

Directory Names with Spaces

If the directory name contains spaces or special characters, you need to either quote the name or escape the spaces with a backslash:

Terminal
mkdir "My Documents"

Or using backslash:

Terminal
mkdir My\ Documents

Both commands create a directory named My Documents.

Create a Directory with a Date or Time Stamp

You can use command substitution to create a directory with the current date or time:

Terminal
mkdir "backup-$(date +%F)"

For example, this creates a directory like backup-2026-01-24.

How to Remove Directories

To remove an empty directory, use the rmdir command:

Terminal
rmdir dirname

If the directory is not empty, use the rm command with the -r option to remove it recursively:

Terminal
rm -r dirname

Quick Reference

CommandDescription
mkdir dirnameCreate a single directory
mkdir dir1 dir2 dir3Create multiple directories
mkdir -p path/to/dirCreate nested directories
mkdir -m 755 dirnameCreate with specific permissions
mkdir -v dirnameCreate and show confirmation

FAQ

What is the difference between mkdir and touch?
mkdir creates directories. The touch command creates empty files or updates the timestamp of existing files. They serve different purposes and are not interchangeable.

What does mkdir -p do?
The -p option creates the entire directory path, including any missing parent directories. Without -p, mkdir fails if a parent directory in the path does not exist. With -p, it also silently succeeds if the target directory already exists.

Is there a difference between a folder and a directory?
No. “Folder” and “directory” mean the same thing. “Folder” is more common in desktop environments and graphical file managers, while “directory” is the standard term in the command line and Linux documentation.

Conclusion

The mkdir command handles everything from creating a single directory to building complex directory trees with brace expansion. For related file operations, see the guides on removing directories , copying files with cp , and listing files with ls .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page