How to Create a New Directory in Ubuntu Linux Terminal Using the mkdir Command

When working within the Ubuntu Linux desktop environment, creating a new folder is as simple as right-clicking and selecting “New Folder.” However, when you are managing a server, connecting via SSH, or simply working efficiently in the command line, you must rely on terminal commands. In Linux terminology, folders are referred to as “directories.” The fundamental tool for creating new directories is the mkdir (make directory) command.

The Basic mkdir Command

The simplest way to use mkdir is to create a single new directory within your current working location.

  1. Open your terminal application (press Ctrl + Alt + T).
  2. Type the command followed by the exact name you want to give the new directory. For example, to create a directory named “projects”, type:
    mkdir projects
  3. Press Enter.

If the command is successful, the terminal will simply return to a new prompt without showing any output. You can verify the directory was created by typing ls to list the contents of your current location.

Handling Spaces in Directory Names

Unlike a graphical interface, the terminal uses spaces to separate commands from arguments. If you attempt to type mkdir my new folder, the system will actually create three separate folders named “my”, “new”, and “folder”.

To create a single directory with spaces in the name, you must enclose the entire name in quotes:
mkdir "my new folder"

Alternatively, standard Linux best practice is to avoid spaces entirely and use hyphens or underscores (e.g., mkdir my-new-folder or mkdir my_new_folder).

Creating Multiple Directories at Once

You can create several separate directories simultaneously by providing multiple names separated by spaces.

For example, to create three directories for a web project, type:
mkdir html css images

Creating Nested Directories (Parent and Child)

One of the most powerful features of mkdir is its ability to create an entire directory tree (a folder inside a folder inside a folder) in a single command. By default, if you try to type mkdir 2024/january/invoices, it will fail unless the “2024” and “january” folders already exist.

To force the system to create any missing parent directories along the path, you must use the -p (parents) flag.

Type: mkdir -p 2024/january/invoices

This single command will instantly create the “2024” folder, create the “january” folder inside it, and finally create the “invoices” folder inside that, saving you from having to run three separate commands.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.