How to Create a Directory in Linux: mkdir Command Examples

Setting up a project layout, organizing files, or preparing a path for a script or configuration file usually starts with the same step: creating a directory. In Linux, you do that from the command line with the mkdir command, short for “make directory”.
This guide covers how to use mkdir to create single and multiple directories, build nested directory trees, set permissions at creation time, and create a directory only when it does not already exist.
Linux mkdir Command Syntax
The syntax for the mkdir command is as follows:
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:
mkdir newdirYou can verify that the directory was created by listing the contents using the ls command
:
ls -ldrwxrwxr-x 2 username username 4096 Jan 20 03:39 newdirWhen 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:
mkdir /tmp/newdirIf 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:
mkdir /root/newdirmkdir: cannot create directory '/root/newdir': Permission deniedmkdir prints shorter error messages, for example mkdir: Permission denied or mkdir: newdir: File exists. The cause and the fix are the same as for the GNU messages shown in this guide.To create a directory in a location owned by root, such as /opt or /srv, prefix the command with sudo
:
sudo mkdir /opt/myappIf you plan to manage files inside that directory as your regular user, change the directory ownership after creating it:
sudo chown "$USER:$(id -gn)" /opt/myappThe -v (--verbose) option tells mkdir to print a message for each created directory:
mkdir -v newdirmkdir: 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:
mkdir /home/linuxize/Music/Rock/GothicIf any of the parent directories do not exist, you will get an error:
mkdir: cannot create directory '/home/linuxize/Music/Rock/Gothic': No such file or directoryThe No such file or directory message refers to the parent path, not to the directory you are creating. In this example, /home/linuxize/Music/Rock does not exist, and mkdir has nowhere to put Gothic.
Instead of creating the missing parent directories one by one, invoke the mkdir command with the -p option. Combine it with -v to print a message for each created directory.
The following command is run from /home/linuxize, where Music already exists but Rock and Gothic do not:
mkdir -pv Music/Rock/Gothicmkdir: created directory 'Music/Rock'
mkdir: created directory 'Music/Rock/Gothic'The Music directory already exists, so mkdir skips it and creates only Rock and Gothic.
How to Create a Directory Only If It Does Not Exist
If you try to create a directory that already exists
and the -p option is not provided, mkdir will print File exists error:
mkdir newdirmkdir: cannot create directory 'newdir': File existsThe command also returns a non-zero exit status. In a shell script that uses set -e, this error stops the script.
When the -p option is used, the command creates the directory only if it does not already exist. If the directory is already there, mkdir -p prints nothing and exits with status 0:
mkdir -p newdirYou can run the same mkdir -p command as many times as you want, and the result is always the same. This makes it the simplest way to create a directory from a Bash script without checking for it first:
DATA_DIR="$HOME/.local/share/myapp"
mkdir -p "$DATA_DIR"If the script needs to know whether the directory was created, test for it with -d before calling mkdir:
if [ ! -d "$DATA_DIR" ]; then
mkdir -p "$DATA_DIR" && echo "Created $DATA_DIR"
fiThe message is printed only if mkdir succeeds.
The -p option skips only existing directories. If a regular file with the same name exists, mkdir -p still fails:
mkdir -p reportmkdir: cannot create directory 'report': File existsTo fix this, rename or remove the file, or choose a different name for the directory.
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:
mkdir -m 700 newdirWhen you combine -m with -p, the mode applies only to the last directory in the path, and only if it is newly created. Existing directories keep their permissions; use chmod to change them. Any parent directories that mkdir creates get the default permissions:
mkdir -p -m 700 secure/keys/private
ls -ld secure secure/keys secure/keys/privatedrwxrwxr-x 3 linuxize linuxize 4096 Oct 5 18:44 secure
drwxrwxr-x 3 linuxize linuxize 4096 Oct 5 18:44 secure/keys
drwx------ 2 linuxize linuxize 4096 Oct 5 18:44 secure/keys/privateOnly private has the drwx------ (700) permissions. If the parent directories need the same mode, change it with chmod after creating them.
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:
mkdir dir1 dir2 dir3The mkdir command also allows you to create a complex directory tree with one command:
mkdir -p Music/{Jazz/Blues,Folk,Disco,Rock/{Gothic,Punk,Progressive},Classical/Baroque/Early}The command above creates the following directory tree:
Music/
|-- Classical
| `-- Baroque
| `-- Early
|-- Disco
|-- Folk
|-- Jazz
| `-- Blues
`-- Rock
|-- Gothic
|-- Progressive
`-- PunkDirectory 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:
mkdir "My Documents"Or using backslash:
mkdir My\ DocumentsBoth 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:
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:
rmdir dirnameIf the directory is not empty, use the rm command
with the -r option to remove it recursively.
The command deletes the directory and everything inside it. Removed files do not go to the trash, so double-check the path before you press Enter:
rm -r dirnameQuick Reference
| Command | Description |
|---|---|
mkdir dirname | Create a single directory |
mkdir dir1 dir2 dir3 | Create multiple directories |
mkdir -p path/to/dir | Create nested directories |
mkdir -p dirname | Create only if it does not exist |
mkdir -m 755 dirname | Create with specific permissions |
mkdir -v dirname | Create 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
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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