Creating a directory on Linux takes one command
To create a new directory, open your terminal and type mkdir followed by the name you want to give the folder. For example, to create a folder called "Documents", you would type:
mkdir Documents
Press Enter, and the directory appears in your current location. That is the entire process. The folder now exists and is ready to hold files or other directories inside it.
Key Takeaways
- The mkdir command creates a single directory with the syntax mkdir foldername.
- Use mkdir -p to create multiple nested directories at once, such as mkdir -p Projects/Work/2024.
- Directory names can contain letters, numbers, hyphens, and underscores, but spaces require quotes around the name.
- You must have write permission in the location where you are creating the directory, usually your home folder by default.
- Use ls to verify the directory was created and cd to move into it.
Creating nested directories in one command
If you need to create multiple folders inside each other — for example, a "Projects" folder containing a "Work" folder containing a "2024" folder — you can do this in a single command instead of creating each one separately.
Type mkdir -p Projects/Work/2024 and press Enter. The -p flag tells Linux to create all the parent directories that do not yet exist. If "Projects" does not exist, Linux creates it. If "Work" does not exist inside "Projects", Linux creates that too. This saves time when you are setting up a folder structure from scratch.
Without the -p flag, the command fails if the parent directories do not already exist. The flag prevents that error and builds the entire path for you.
Naming directories correctly
Directory names on Linux are case-sensitive, meaning "Documents", "documents", and "DOCUMENTS" are three different folders. Choose a naming style and stick with it to avoid confusion later.
Names can contain letters, numbers, hyphens, and underscores. Avoid spaces in directory names because they complicate commands — if you must use a space, wrap the entire name in quotes: mkdir "My Documents". Most people use hyphens or underscores instead, like My-Documents or My_Documents, to keep commands simpler.
Do not start a directory name with a dot unless you want it hidden from normal view. A directory named .hidden will not show up when you list files with ls — you need ls -a to see it. This is useful for configuration folders but confusing for everyday work.
Checking that your directory was created
After you run the mkdir command, verify the directory exists by listing the contents of your current location. Type ls and press Enter. Your new directory should appear in the list.
If you created nested directories with mkdir -p, you can see the full structure by typing ls -R (the -R flag means "recursive" and shows all folders and subfolders). This confirms that all the directories you intended were actually created.
Moving into your new directory
Once the directory exists, you can move into it using the cd command, which stands for "change directory". Type cd Documents to enter the Documents folder you just created.
Your terminal prompt usually changes to show your current location. If you created nested directories, you can move into them step by step — cd Projects, then cd Work, then cd 2024 — or jump directly to the deepest folder with cd Projects/Work/2024. Type pwd (print working directory) at any time to see exactly where you are in the folder structure.
Fixing common mistakes
If you see an error message saying "Permission denied", you do not have write permission in the location where you are trying to create the directory. This usually happens if you are trying to create a folder in a system directory that requires administrator access. Create your directory in your home folder instead, which you always have permission to modify.
If you see "File exists", you tried to create a directory with a name that already exists in that location. Choose a different name or use mkdir -p if you are creating nested directories and one of the parent folders already exists — the -p flag prevents this error by skipping directories that are already there.
If you accidentally created a directory in the wrong location, use rmdir foldername to remove it (the folder must be empty). Then create it in the correct location.
Organizing multiple directories at once
When you are setting up a project or workspace, you often need several folders at the same level. You can create them all in one command by listing them after mkdir, separated by spaces:
mkdir Documents Photos Videos Music
This creates four directories — Documents, Photos, Videos, and Music — all in your current location in a single step. This is faster than running mkdir four separate times and keeps your workspace organized from the start.
Frequently Asked Questions
Can I create a directory with a space in the name?
Yes, but you must wrap the name in quotes: mkdir "My Documents". However, most people avoid spaces in directory names because they make commands harder to type. Use hyphens or underscores instead: mkdir My-Documents or mkdir My_Documents.
What is the difference between mkdir and mkdir -p?
mkdir creates a single directory and fails if the parent folder does not exist. mkdir -p creates all parent directories as needed and does not fail if the directory already exists. Use -p when you are building a folder structure with multiple levels.
How do I see if my directory was created?
Type ls to list all directories and files in your current location. Your new directory should appear in the list. If you created nested directories, use ls -R to see the full structure with all subfolders.
Can I create a directory in a location other than where I am right now?
Yes. Instead of just the directory name, provide the full path: mkdir /home/username/Documents/NewFolder. Replace the path with the actual location where you want the directory created. You must have write permission in that location.
What happens if I try to create a directory that already exists?
You get an error message saying "File exists". If you are using mkdir -p to create nested directories, the command skips any directories that already exist and creates only the new ones, so no error occurs.