The Basic Command to Make a New Directory

To create a directory in Linux, use the mkdir command followed by the name you want to give the directory. Open your terminal and type mkdir my_folder, then press Enter. Linux will create a new directory called "my_folder" in your current location immediately.

The directory appears right away. You can verify it exists by typing ls and pressing Enter — your new directory will show in the list of files and folders in that location. If you want to see more details about the directory, including when it was created and its permissions, type ls -l instead.

Key Takeaways

  • The mkdir command creates a single directory: type mkdir folder_name and press Enter.
  • Use mkdir -p to create multiple nested directories at once, like mkdir -p parent/child/grandchild.
  • Directory names can include letters, numbers, underscores, and hyphens, but spaces require quotes around the name.
  • You need write permission in the location where you are creating the directory — usually your home folder or a folder you own.
  • Use pwd to see where you are before creating a directory, so you know exactly where it will appear.

Creating Multiple Nested Directories at Once

If you need to create a chain of directories — for example, projects/work/2024 — you can do it in one command using the -p flag. Type mkdir -p projects/work/2024 and press Enter. Linux will create all three directories, even if "projects" and "work" do not exist yet.

Without the -p flag, mkdir will fail if the parent directory does not exist. The -p flag stands for "parents" and tells Linux to create any missing parent directories automatically. This saves time when you are setting up a folder structure for a new project or organizing files into multiple levels.

Naming Your Directory Correctly

Directory names in Linux are case-sensitive, so "MyFolder", "myfolder", and "MYFOLDER" are three different directories. Use lowercase letters and underscores or hyphens to separate words — this is the standard Linux convention and avoids confusion when you are typing commands later.

If you want a directory name with spaces, wrap the entire name in quotes: mkdir "my documents". However, names without spaces are easier to work with in the terminal, since you would need to type quotes or backslashes every time you reference the directory later. For most purposes, mkdir my_documents or mkdir my-documents is simpler and cleaner.

Checking Your Current Location Before Creating

Before you create a directory, know where you are in the file system. Type pwd (print working directory) and press Enter — it shows the full path of your current location. This prevents you from creating directories in the wrong place and helps you understand the structure of your file system.

For example, if you type pwd and see /home/username, then any directory you create will appear there. If you see /home/username/Documents, new directories will appear in Documents instead. Checking your location first takes just a second and saves you from having to search for a directory you created in an unexpected place.

Moving to a Different Location First

To create a directory in a specific folder, navigate there first using the cd command. Type cd Documents to move into your Documents folder, then type mkdir new_project. The new directory will appear inside Documents, and you can start working with it right away.

You can also create a directory in a specific location without moving there. Type mkdir /home/username/Documents/new_project using the full path. This works if you know the exact location but do not want to navigate there first. Both approaches work — choose whichever feels more natural to you.

What to Do If You Get a Permission Error

If you type mkdir and see "Permission denied", you do not have write permission in that location. This usually happens when you try to create a directory in a system folder or a folder owned by another user. The error message means Linux is protecting those folders from accidental changes.

Create the directory in your home folder instead, or ask the folder owner to give you permission. You can see who owns a folder by typing ls -l — the owner's name appears in the third column. Do not use sudo to force permission unless you are certain you should be creating directories there, as this can cause problems with file ownership and system security.

Frequently Asked Questions

Can I create a directory with spaces in the name?

Yes, but you must put the name in quotes: mkdir "my folder". However, spaces make the directory harder to work with in the terminal because you will need to quote the name every time you reference it. Names with underscores or hyphens instead are simpler: mkdir my_folder or mkdir my-folder.

What is the difference between mkdir and mkdir -p?

Plain mkdir creates a single directory and fails if the parent directory does not exist. The -p flag creates all parent directories automatically. Use mkdir -p when you need to build a chain of nested folders in one command.

How do I create a directory in a location I do not have permission for?

You cannot create a directory where you do not have write permission. Create it in your home folder or a folder you own instead. If you need access to a specific location, ask the folder owner or administrator to give you write permission for that folder.

Can I see the directory I just created right away?

Yes. Type ls and press Enter to list all files and directories in your current location. Your new directory will appear in the list. You can also type ls -l to see more details, including when it was created and its permissions.

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

Linux will show an error message saying the directory already exists and will not create a duplicate. If you use mkdir -p with a path that includes an existing directory, it will not fail — it will create only the directories that do not exist yet.