mkdir creates directories. Type mkdir test-dir in a terminal, hit Enter, and you've got a new directory in your current location. That's the whole trick. The name is literally "make directory." It ships with GNU coreutils, so it's on every Linux distribution, every BSD, macOS, and pretty much anything Unix-like you'll ever SSH into. And yes โ "directory" and "folder" mean the same thing here. Graphical file managers call them folders; the shell and the filesystem call them directories. Same object, different vocabulary.
In this tutorial, we will go through the mkdir command in Linux. Whether it's for personal or for work, everyone loves to create directories in Linux to keep things organized in one place. One of the most used Linux commands to accomplish this task is mkdir.
Before discussing the mkdir command in Linux operating system, it's important to know what exactly Linux and Unix are.
๐ง What is Linux?
Linux is widely known as an open-source operating system. Unlike Windows and macOS which require a paid activation key, Linux has granted anyone access to its system for any purpose without any charge. It has been named the most popular OS on earth despite Microsoft and Apple's dominance in most computers today. Devices that have been a huge part of everyone's daily lives, such as Android phones, high-tech cars, smart appliances, and company servers, are powered by Linux.
To gain a deeper understanding of this versatile operating system and its importance in powering modern technology, check out our comprehensive guide on What is Linux. It covers the history, features, and benefits that make Linux a favorite among developers and tech enthusiasts worldwide.
This operating system, unknown to many, hosts the world's top supercomputers and even the stock exchange. By purchasing a Linux VPS, you can have full control over your hosting environment and tailor it to your specific needs, allowing you to optimize performance and ensure reliable uptime for your applications or website.
๐ง What is UNIX?
But right before Linux was born, there was another operating system that tried to change the world. Bell Labs Research introduced Unix in the 1970s as an OS for computers that run multi-user programs. Back then, Unix was able to pave its way towards worldwide popularity for being the first compact operating system designed in C Programming Language. However, its fame started to fade away when Linux began to rise in 1994 as Unix's free clone.
โ๏ธ Difference Between Linux and UNIX

Linux and Unix have many similarities, so it's no surprise that many people can't still exactly differentiate the two up until today. But to mention a few differences, Linux is completely free while Unix provides access to copyright holders only. Unix is compatible with some computer files but lesser compared to what Linux can support. When it comes to security, both of them almost provide the same level of cyber protection.
If you get used to Windows or macOS for a long time, navigating through Unix and Linux's interfaces will surely bring you to an extremely different world. Simple tasks such as creating a folder for your files will suddenly become an unfriendly errand. Also adding more security for your Linux or UNIX operating system is different from Windows and macOS โ here you can read our guide on how to choose a secure password.
If such easy tasks only take you a few minutes to complete on your MacBook, Unix and Linux will ask more time than you expect. You have to go into your device's user command and enter the mkdir command on the designated line. Does it sound foreign to you? It's alright. Take it slowly and read through the step-by-step guide below.
๐ What is Linux mkdir Command?
In the simplest explanation, mkdir stands for 'make directory' and is a typical command used to create Linux directories on devices powered by Linux or Unix. If this seems unclear, the directory is the Unix and Linux counterpart for the macOS and Windows folders. It also has the purpose of storing, preserving, and protecting files installed on the computer.

However, directories are far different from folders when it comes to the files they curate. Directories are most often used for keeping sensitive and confidential data, including rosters of diverse file names as well as their equivalent inode numbers. There are quite a number of important directories in Linux. Every inode number in the system represents a specific inode that holds all the relevant information about the file. It synchronizes all the computer data on the operating system.
Aside from generating directories for new loads of incoming files, the mkdir Linux command also allows the users to assign access and creation permission for each directory. Before a user can create directories on your computer using the mkdir command, they first need to seek consent from the parent directory; otherwise, the attempt will be instantly denied.
Are you ready to create folders in Linux? Read below the step-by-step Linux mkdir command guide.
๐ mkdir Command Syntax
mkdir [OPTION]... DIRECTORY...
Two parts to remember:
- OPTION โ flags that change behavior, like
-por-m 755. Optional. - DIRECTORY โ one or more names or paths. Required, and you can list as many as you want.
The trailing dots in the man page mean "repeatable." So mkdir a b c is perfectly valid and creates three directories in one shot.
๐ How to Create a Directory in Linux
Pass the name of the directory you're about to generate with the mkdir command. See the example below.
mkdir [dir-name]
mkdir test-dir
That creates test-dir inside your current working directory. Not sure where you are? Run pwd first โ one wrong assumption about your working directory and you've littered folders across a document root.
You can also use an absolute path, which starts from the filesystem root and ignores where you currently are:
mkdir /home/user/projects
mkdir /var/www/example.com
A relative path is anything that doesn't start with / โ it's resolved from your current location. mkdir ../backups creates a directory one level up. Both styles work; absolute paths are safer in scripts and cron jobs.

๐ฆ How to Create Multiple Directories at Once
You can create multiple directories on your device at once. Pass the file names of the directories you're about to create with the mkdir command, separated by spaces:
mkdir goo aar raz
ls
Result:
goo aar raz
Now here's a trick worth knowing โ brace expansion. It's a shell feature, not a mkdir feature, but the two are made for each other:
mkdir website/{images,css,js}
mkdir -p app/{logs,cache,tmp}
The shell expands the braces before mkdir ever sees them, so the second command becomes mkdir -p app/logs app/cache app/tmp. No spaces inside the braces. If you add one, bash treats it as a separate argument and you'll end up with a directory literally named cache floating in the wrong place.
๐ฒ How to Create Nested Directories with mkdir -p
Try this without a flag and it fails:
$ mkdir project/src/components
mkdir: cannot create directory 'project/src/components': No such file or directory
Plain mkdir refuses to invent missing parents. Add -p (or --parents) and it builds the whole chain:
mkdir -p project/src/components
Two behaviors worth internalizing. First, existing parents are left alone โ -p only creates what's missing. Second, -p doesn't complain if the target already exists; it exits cleanly with status 0. That makes it the correct choice inside deployment scripts, where you want "make sure this path exists" rather than "create this or explode."

๐ Useful mkdir Options Explained
Note that the command comes with many options, and here we will cover the most useful ones:
| Option | What it does | Example |
-p, --parents |
Creates missing parent directories; no error if the path exists | mkdir -p app/logs/nginx |
-m, --mode |
Sets permissions at creation time, ignoring the umask | mkdir -m 755 public_html |
-v, --verbose |
Prints a line for every directory created | mkdir -v demo |
--help |
Shows all flags and exits | mkdir --help |
--version |
Prints the coreutils version | mkdir --version |
The -v option pairs beautifully with -p. Run mkdir -pv a/b/c and you'll see each level reported as it's created โ genuinely useful for debugging a provisioning script.
How to Check Complete Operations Performed by Linux mkdir
The mkdir command can show the complete details regarding the operations it's about to perform using the verbose option:
mkdir -v [dir]
๐ How to Set Permissions When Creating a Directory
Normally a new directory gets 0777 minus your umask โ usually 755. The -m flag overrides that:
mkdir -m 755 public_html
mkdir -m 700 private-config
Quick decoder for the three modes you'll use 95% of the time:
- 700 โ owner only. Use it for SSH keys, config folders with credentials, private backups.
- 755 โ owner writes, everyone reads and enters. The default for web document roots.
- 775 โ owner and group write. Handy for shared deploy directories where a group of users or a CI account needs access.
One caveat: -m only applies to the final directory when you use -p. Intermediate parents get the umask default. If you need consistent permissions the whole way down, follow up with chmod -R. Ownership is a separate concern entirely โ that's chown territory.
โ ๏ธ Common mkdir Errors and How to Fix Them
Permission denied
mkdir: cannot create directory 'secure': Permission denied
You need both write and execute permission on the parent directory. Check it with ls -ld . or ls -ld /var/www. If the parent belongs to root, prefix with sudo โ but only when it genuinely should be root-owned. Creating your app files as root and then wondering why the web server can't write to them is a headache you'd rather avoid.
File exists
mkdir: cannot create directory 'demo': File exists
Something already occupies that name โ a directory, a regular file, even a symlink. Run ls -ld demo to see what it is. In scripts, add -p to suppress the error.
No such file or directory
A parent in the path doesn't exist, or there's a typo. Use -p, or fix the path.
Names with spaces
mkdir my new folder creates three directories. Quote it or escape it:
mkdir "my new folder"
mkdir my\ new\ folder
On servers, honestly, don't. Use hyphens or underscores and save yourself a lifetime of quoting.
โ How to Verify That the Directory Was Created
$ ls
projects test-dir
$ ls -ld test-dir
drwxr-xr-x 2 user user 4096 Feb 11 10:22 test-dir
$ tree project
project
โโโ src
โโโ components
ls confirms existence, ls -ld shows permissions and ownership without listing contents, and tree (install it separately on most distros) visualizes nested structures. mkdir is silent on success, so no output means it worked.
๐ป Practical Examples on a Linux Server
mkdir -p /var/www/example.com/{public,logs,tmp}
mkdir -m 700 -p /opt/app/config
mkdir -p /backups/$(date +%F)
That last one stamps a date-based backup folder like /backups/2025-02-11, which makes retention scripts trivial. On a fresh Linux VPS, I usually create the document root, a logs directory, and a locked-down config directory in three commands before touching anything else.
๐ฅ๏ธ mkdir vs Creating Folders in a GUI
A file manager is fine for one folder on your desktop. Right-click, new folder, done.
But on a remote server you often have no GUI at all, and even when you do, mkdir -p site/{css,js,img,fonts} beats fourteen mouse clicks. The terminal also scales โ the same line works in a Bash script, a Dockerfile, or an Ansible task. That's the real reason sysadmins never go back.
๐ Best Practices and Related Commands
- Descriptive, lowercase names. No spaces on servers.
- Always use
-pin scripts so re-runs stay idempotent. - Set restrictive modes (
700) on anything holding secrets. - Run
pwdbefore creating directories in production.
Directory work rarely happens alone. You'll reach for ls, cd, and pwd for navigation; rmdir for empty directories and rm -r for full ones; cp -r and mv for copying and renaming; chmod and chown for permissions and ownership. For the exhaustive flag list, the GNU Coreutils documentation and the mkdir man page are the sources of truth.
Learn plain mkdir, then -p, then -m. That covers nearly everything you'll ever need. Browse more Linux command tutorials to build out the rest of your toolkit.
๐ฏ Final Thought
Whether it's about creating a Linux directory, it's always important to keep essential computer files in a safe and secure place. They are virtual assets, so losing them once would mean losing them forever. Use the guide above and take every pointer seriously โ creating directories using the mkdir command in Linux will become as easy as creating folders on Windows and macOS.
For businesses or users seeking enhanced performance and control, Linux Dedicated Servers provide a reliable environment to manage your directories and files efficiently. Learn more about their benefits and why they're a popular choice in the hosting world.
People Are Also Reading:


Leave A Comment