The mkdir command creates a new folder in Linux

To create a directory in Linux, open a terminal and type mkdir followed by the name you want. For example, mkdir Documents creates a folder called Documents in your current location. The command works when ready — you will not see a confirmation message, but the folder appears right away.

The folder appears in whatever directory you are already in. If you are in your home folder and type mkdir Photos, the Photos folder lands in your home directory. To check where you are, type pwd (print working directory) and press Enter — it shows your current path.

You can also create a directory with a path. Type mkdir /home/username/NewFolder to create NewFolder in a specific location without moving there first. Replace username with your actual username.

Key Takeaways

  • The mkdir command creates a single new directory: type mkdir FolderName and press Enter.
  • Use mkdir -p path/to/nested/folders to create multiple levels of directories at once, instead of making each one separately.
  • Check your current location with pwd before creating a directory, so you know where it will appear.
  • Directory names can include letters, numbers, hyphens, and underscores, but spaces require quotes: mkdir "My Documents".

Creating multiple nested directories at once

If you need to build a folder structure with several levels — like Projects/2024/January/Reports — you can create them all in one command instead of making each folder separately. Use the -p flag: mkdir -p Projects/2024/January/Reports.

The -p flag tells mkdir to create parent directories as needed. Without it, you would get an error if Projects does not already exist. With -p, mkdir creates Projects first, then 2024 inside it, then January, then Reports — all from one command.

Naming directories so you can find them later

Directory names should describe what goes inside. Use lowercase letters and numbers when possible — mkdir project_files or mkdir backup_2024 — because Linux treats uppercase and lowercase as different. A folder named Documents is not the same as documents.

Avoid spaces in directory names. If you must use a space, wrap the name in quotes: mkdir "My Photos". Hyphens and underscores work without quotes and are easier to type: mkdir my-photos or mkdir my_photos.

Keep names short enough to type without mistakes, but specific enough that you remember what they hold. mkdir work is too vague if you have multiple jobs. mkdir freelance_clients_2024 tells you exactly what is inside.

Moving into a directory you just created

After you create a directory, you stay in your current location. To move into the new folder, use the cd command: cd Documents moves you into the Documents folder. Type pwd to confirm you are there.

To move back up one level, type cd .. (cd space dot dot). To jump directly to your home folder from anywhere, type cd with no path. These shortcuts work from any directory.

Listing directories to see what you created

After creating folders, you can see them with the ls command. Type ls and press Enter to list everything in your current directory. Folders appear in the output along with files.

For a clearer view that shows which items are directories, use ls -l (ls space hyphen L). This shows a detailed list where directories start with the letter d on the left side. You can also use ls -la to include hidden files and folders that start with a dot.

Removing directories you no longer need

If you create a directory by mistake or no longer need it, use rmdir FolderName to delete it. The folder must be empty — if it contains files or other directories, rmdir will refuse to delete it and show an error.

To delete a directory that contains files, use rm -r FolderName instead. The -r flag means recursive, which deletes the folder and everything inside it. Be careful with this command because deleted files do not go to a trash folder — they are gone permanently.

Organizing directories into a logical structure

Before creating many directories, sketch out a plan. Decide what top-level folders you need — perhaps Documents, Projects, Photos, and Backups. Then decide what goes inside each one. This prevents creating dozens of folders scattered randomly.

A common structure looks like this: a top-level folder for the year (2024), with subfolders for months (January, February), and inside those, folders for specific projects or topics. You can build this with one command: mkdir -p 2024/{January,February,March}/{Projects,Archive}. The curly braces create multiple folders at each level.

Keep your structure shallow enough to navigate quickly. If you need more than three or four levels deep, you are probably organizing too finely. You should be able to find what you need in a few cd commands.

Frequently Asked Questions

What happens if I try to create a directory that already exists?

Linux shows an error message saying the directory already exists and does not create a duplicate. If you use mkdir -p with a path that includes an existing directory, it skips the existing one and creates only the new folders you need.

Can I create a directory with spaces in the name?

Yes, but you must put the name in quotes: mkdir "My Documents". Without quotes, Linux treats each word as a separate directory name. Hyphens and underscores work without quotes and are simpler to type.

How do I see hidden directories in Linux?

Hidden directories start with a dot and do not appear with a plain ls command. Type ls -a to show them. You can create hidden directories the same way as regular ones — mkdir .hidden_folder — and they work identically.

What is the difference between mkdir and mkdir -p?

Plain mkdir creates one directory and fails if the parent directory does not exist. mkdir -p creates all parent directories as needed, so you can build an entire nested structure in one command without errors.

Can I undo a directory deletion?

No. Once you delete a directory with rmdir or rm -r, it is gone permanently. Linux does not have a trash or recycle bin for command-line deletions. Always double-check the directory name before running a delete command.