How to Make New Directories in Linux

Suraj Joshi Feb 02, 2024
  1. mkdir Command
  2. Create a New Directory Using mkdir Command
  3. Set Permissions While Creating a Directory
  4. Create Multiple Directories
How to Make New Directories in Linux

To make new directories in Linux, we can use either File Manager or Terminal. To create new directories using the terminal, we use the mkdir command.

mkdir Command

mkdir command creates directories using the Command Line Interface and sets the directories’ permissions.

Syntax:

mkdir [OPTION] [DIRECTORY]

Here, OPTION includes options while creating directories, and DIRECTORY represents one or more directories’ names to be created.

While running this command, we must be sure that we have enough permissions; otherwise, we may get a permission denied error.

Create a New Directory Using mkdir Command

mkdir newdir

It creates a new directory with the name newdir in the current working directory.

To verify the creation of the directory, we can use ls -l command:

ls -l

Output:

drwxr-xr-x 2 zeppy zeppy 4096 Sep  1 20:00 newdir

To create a directory in other locations rather than the current working directory, we need to provide the absolute or relative path to the parent directory.

mkdir test/abc

This creates a new directory abc inside the test directory. Here, the test directory must be inside the current working directory.

However, if the parent directory test doesn’t exist, we get No such file or directory error. To create parent directories if they don’t exist, we could use the -p option.

mkdir -p test/abc/newdir

In this case, even if any of the parent directories test and abc do not exist, the command will create missing directories in addition to the newdir directory.

Set Permissions While Creating a Directory

To set permissions while creating the directory, we use the -m option. The syntax for setting permission is the same as of chmod command.

mkdir -m 700 test

This creates a new directory named test with 700 permissions, meaning the directory’s creator can only access the directory.

Create Multiple Directories

To create multiple directories, we use the mkdir command followed by directories’ names to be created separated by space.

mkdir tennis football swimmimg

This will create directories tennis, football, and swimming in the current working directory.

Author: Suraj Joshi
Suraj Joshi avatar Suraj Joshi avatar

Suraj Joshi is a backend software engineer at Matrice.ai.

LinkedIn

Related Article - Linux Files and Directories