The basic command to create a folder

To create a folder in Linux, use the mkdir command followed by the name you want to give the folder. Open your terminal and type mkdir foldername, then press Enter. The folder appears in your current location — usually your home directory if you just opened the terminal.

The name can be a single word like mkdir Documents or multiple words if you use quotes: mkdir "My Projects". Linux is case-sensitive, so mkdir documents and mkdir Documents create two different folders.

If the folder already exists, mkdir will tell you it cannot create it. You can then choose a different name or navigate into the existing folder instead.

Key Takeaways

  • The mkdir command creates a single folder: type mkdir foldername and press Enter.
  • Folder names with spaces need quotes around them, like mkdir "My Documents".
  • Use mkdir -p path/to/nested/folders to create multiple levels of folders at once, including parent folders that do not yet exist.
  • Check what folder you are currently in by typing pwd before you create, so the new folder lands in the right place.
  • List the contents of your current folder with ls to confirm the new folder was created.

Creating nested folders all at once

If you need to create a folder inside a folder that does not yet exist, use the -p flag. Type mkdir -p Projects/Work/2024 and mkdir will create all three levels — Projects, then Work inside it, then 2024 inside Work — even if none of them existed before.

Without the -p flag, mkdir fails if the parent folder does not exist. The -p flag stands for "parents" and tells mkdir to create any missing parent folders along the way. This saves you from having to create each level separately.

The -p flag is also safe to use even if some or all of the folders already exist. If Projects exists but Work does not, mkdir -p will create only Work and 2024, leaving Projects untouched.

Checking your current location before creating

Before you create a folder, know where you are in the file system. Type pwd (print working directory) and press Enter. The terminal shows the full path of your current location, like /home/username or /home/username/Documents.

This matters because mkdir creates the folder right where you are standing. If you want the folder in a specific place, navigate there first using cd foldername to move into a folder or cd .. to move up one level to the parent folder.

You can also create a folder in a different location without navigating there by typing the full path: mkdir /home/username/Documents/NewFolder. This is useful when you know exactly where you want the folder but do not want to change your current working directory.

Verifying the folder was created

After you run mkdir, type ls and press Enter to list everything in your current folder. You should see the new folder name in the output. The folder appears as a line of text with no file extension — just the name you gave it.

If you used mkdir with the -p flag to create nested folders, type ls -R to see the full tree of all the folders you just created, including the ones nested inside each other. The -R flag stands for "recursive" and shows you every level of the folder structure you built.

Handling special characters and spaces

Folder names with spaces must be wrapped in quotes. Type mkdir "My New Folder" rather than mkdir My New Folder, which would create three separate folders named My, New, and Folder.

Avoid special characters like asterisks, question marks, forward slashes, and backslashes in folder names — Linux treats them as commands or path separators. Stick to letters, numbers, hyphens, and underscores. If you accidentally create a folder with a problematic name, use rm -r "foldername" to remove it and try again with a simpler name.

What to do if mkdir says the folder already exists

If you run mkdir and get an error saying the folder exists, you have two choices. You can create a folder with a different name by adding a number or date to it — for example, mkdir Projects2 or mkdir Projects_2024. Or you can navigate into the existing folder using cd Projects and create subfolders inside it instead.

If you want to use the existing folder but are not sure what is in it, type ls Projects to see its contents without entering it. This lets you decide whether to reuse the folder or create a new one with a different name.

Frequently Asked Questions

Can I create a folder with spaces in the name?

Yes, but you must put the entire name in quotes. Type mkdir "My Documents" instead of mkdir My Documents. Without quotes, Linux treats each word as a separate folder name.

What is the difference between mkdir and mkdir -p?

mkdir creates a single folder and fails if the parent folder does not exist. mkdir -p creates the folder and any missing parent folders along the way. Use -p when you need multiple levels of folders built at once.

How do I create a folder in a different location without navigating there?

Type the full path: mkdir /home/username/Documents/NewFolder. Replace the path with the actual location where you want the folder. You do not have to be in that location to create a folder there.

Can I undo mkdir if I create a folder by mistake?

Yes. Type rmdir foldername to remove an empty folder. If the folder has files or subfolders in it, use rm -r foldername instead. Be careful with rm -r because it deletes everything inside without asking for confirmation.

What happens if I use uppercase and lowercase letters in the folder name?

Linux treats them as different names. mkdir Documents and mkdir documents create two separate folders. Choose one style and stick with it to avoid confusion.