The Basic Command to Create a Directory

To create a directory on Linux, use the mkdir command followed by the name you want to give the folder. Open your terminal and type this:

mkdir my_folder

That command creates a single folder called "my_folder" in whatever location you are currently in. The folder appears when ready — there is no confirmation screen or extra step. If you want to verify it worked, type ls to list everything in your current location, and you will see the new folder listed.

The folder name can contain letters, numbers, underscores, and hyphens. Avoid spaces in folder names on Linux because spaces require extra typing later when you navigate to that folder. Use underscores or hyphens instead: my_documents or my-documents both work better than my documents.

Key Takeaways

  • The mkdir command creates a single folder, and mkdir -p creates multiple nested folders at once.
  • You can create a folder anywhere you have write permission, but your home directory is the safest place to start.
  • Folder names should avoid spaces — use underscores or hyphens instead so you do not have to type quotes later.
  • The pwd command shows you where you are right now, so you know which folder your new directory will land in.

Creating Multiple Nested Folders at Once

If you need to create a folder structure with multiple levels — for example, a "documents" folder containing a "2024" folder containing a "taxes" folder — you can build the whole structure in one command using the -p flag:

mkdir -p documents/2024/taxes

Without the -p flag, mkdir fails if the parent folder does not exist yet. The -p flag means "create parent folders as needed", so it builds documents first, then 2024 inside it, then taxes inside that. All three folders are created in a single command.

This is much faster than creating each folder separately. It also prevents the common mistake of forgetting to create a parent folder first.

Understanding Where Your New Directory Goes

When you type a mkdir command, the new folder appears in your current working directory — the folder you are currently inside in the terminal. If you are not sure where that is, type pwd (which stands for "print working directory") and the terminal shows you the full path.

Most of the time, you want to create folders in your home directory, which is where your personal files live. You can navigate there by typing cd ~ (the tilde ~ is a shortcut for your home directory). After that, any mkdir command puts the new folder in your home directory.

If you want to create a folder in a specific location without navigating there first, include the path in the mkdir command:

mkdir ~/documents/work_files

This creates a "work_files" folder inside your home directory's documents folder, no matter where you are currently located in the terminal.

Permissions and Why You Cannot Create Folders Everywhere

Linux restricts who can create folders in different locations. You can always create folders in your home directory and its subfolders. You cannot create folders in system directories like /etc or /usr without special permission (called "root" or "sudo" access).

If you try to create a folder somewhere you do not have permission and the command fails, the terminal shows an error message like "Permission denied". The solution is to create the folder in your home directory instead, or ask your system administrator for permission to write to that location.

For organizing your own files, you should never need to create folders outside your home directory. All your personal documents, downloads, and projects belong in your home directory or its subfolders.

Naming Conventions That Make Folders Easier to Use

Linux is case-sensitive, which means MyFolder, myfolder, and MYFOLDER are three different folders. Pick one style and stick with it. Many people use all lowercase with underscores (my_folder) because it is faster to type and less error-prone.

Avoid special characters like asterisks, question marks, forward slashes, and quotation marks in folder names. These characters have special meaning in Linux and cause problems when you try to navigate to or rename the folder later. Stick to letters, numbers, underscores, hyphens, and periods.

Give folders names that describe what goes inside them. tax_documents_2024 is more useful than stuff or folder1. When you come back to your files months later, a clear name saves you time searching.

Creating Folders with Specific Permissions

By default, mkdir creates folders that only you can read and write to — other users on the same computer cannot access them. This is the right setting for personal files. If you need to create a folder that other users can access, you can set permissions when you create it using the -m flag:

mkdir -m 755 shared_folder

The numbers 755 mean "the owner can read, write, and enter; everyone else can read and enter but not write". For most personal use, you do not need to worry about this. The default permissions are find and appropriate.

If you create a folder and later realize you need to change who can access it, you can use the chmod command to adjust permissions. But for organizing your own files, the default settings work fine.

Troubleshooting Common Directory Creation Problems

If mkdir tells you "File exists", a folder with that name already exists in your current location. Check what is already there by typing ls, and either use a different name or navigate into the existing folder if that is what you intended.

If mkdir says "No such file or directory", you are trying to create a nested folder structure but the parent folder does not exist. Use the -p flag to create all the parent folders automatically: mkdir -p path/to/new/folder.

If mkdir says "Permission denied", you are trying to create a folder in a location where you do not have write access. Create the folder in your home directory instead, or ask your system administrator for permission to write to that location.

Frequently Asked Questions

Can I create a folder with spaces in the name?

Technically yes, but you have to put the name in quotes: mkdir "my folder". However, this creates extra work later because you have to type the quotes every time you navigate to that folder. It is easier to use underscores or hyphens instead: mkdir my_folder.

What is the difference between mkdir and mkdir -p?

Regular mkdir creates a single folder and fails if the parent folder does not exist. The -p flag creates all parent folders as needed, so mkdir -p a/b/c creates folders a, b, and c even if a and b did not exist before. Use -p when you want to build a whole folder structure at once.

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

Include the path in the mkdir command. mkdir ~/documents/new_folder creates a folder in your documents directory. mkdir /home/username/downloads/archive creates a folder in the downloads directory. The tilde ~ is a shortcut for your home directory.

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

Yes. Use the rmdir command to delete an empty folder: rmdir my_folder. If the folder contains files, use rm -r my_folder instead (the -r flag means "recursive" and deletes the folder and everything inside it). Be careful with rm -r because deleted files cannot be recovered.

Do I need to use sudo to create folders?

No, not for your personal files. You can create folders in your home directory without sudo. You only need sudo if you are trying to create a folder in a system directory like /etc or /usr, which you should not do for organizing personal files. If a command requires sudo, you are probably in the wrong location.