Create a New Directory in Mac Terminal

The Terminal provides several commands for managing directories, but the most common one for creating a new directory is mkdir.

In this tutorial, we will guide you through the steps to create a new directory, along with some advanced options for creating multiple directories at once and setting permissions.

Basic Command for Creating a Directory

The most straightforward way to create a new directory is by using the mkdir command. The syntax for this command is simple:

mkdir new_directory_name

In this example, new_directory_name is the name you want to give the new folder. For example, if you want to create a directory called Projects, you would use:

mkdir Projects

This command will create a new directory named Projects in your current working directory. You can verify that the directory was created by listing the contents of the directory using the ls command:

ls

If the directory was created successfully, you’ll see Projects listed among your files and folders.

Create a New Directory in Mac Terminal - Using mkdir command

Creating a Directory in a Specific Location

If you want to create a directory in a location other than your current directory, you can provide the full path to the directory. For example, to create a directory called Work inside the Documents folder, you would use:

mkdir /Users/yourusername/Documents/Work

Make sure to replace yourusername with your actual username. This command will create the Work directory inside the Documents folder, regardless of your current working directory.

Create a New Directory in Mac Terminal - At absolute path

Creating Multiple Directories at Once

If you need to create multiple directories at once, you can do so by specifying the directory names in a single mkdir command, separated by spaces. For example:

mkdir Project1 Project2 Project3

This command will create three directories—Project1, Project2, and Project3—all within the current directory.

Create a New Directory in Mac Terminal - Creating Multiple Directories at Once

Creating Nested Directories

Sometimes you might want to create a directory along with several subdirectories in one command. The -p option allows you to create parent directories and subdirectories at the same time. For example:

mkdir -p Projects/2024/January

This command creates a Projects directory with a subdirectory named 2024, which in turn contains a subdirectory named January. The -p option ensures that all necessary parent directories are created if they don’t already exist.

Setting Permissions While Creating a Directory

You can also set permissions for a directory as you create it by using the -m option followed by the desired permission value. For example, to create a directory with read, write, and execute permissions for the owner, and read and execute permissions for others, you can use:

mkdir -m 755 new_directory

This command creates a directory called new_directory with the specified permission settings. The permission value 755 means:

  1. The owner has read, write, and execute permissions.
  2. Group members and others have read and execute permissions, but not write permissions.