mkdir: Making a New Directory in Linux

The mkdir command in Linux is a basic and essential tool for managing files and directories. As a user of a Linux system, it is important to understand the mkdir command, how to use it, and the various options available. This article aims to provide a comprehensive guide to the mkdir command and its uses in Linux.

What is the mkdir Command in Linux?

The mkdir command is used to create a new directory in Linux. The name “mkdir” stands for “make directory.” With the mkdir command, you can create a new directory, or multiple directories at once, in your file system. This command is available in all major Linux distributions, including Debian, Ubuntu, Fedora, and CentOS.

Syntax of the mkdir Command

The basic syntax of the mkdir command is simple and straightforward. To create a new directory using the mkdir command, simply type the following command in your terminal:

mkdir directory_name

Where directory_name is the name of the directory you want to create.

Options of the mkdir Command

The mkdir command has several options available that allow you to customize the behavior of the command. Some of the most commonly used options include:

-p (–parents)

The -p or –parents option allows you to create a directory along with its parent directories if they do not exist. For example, if you want to create a directory /home/user/new_dir but /home/user does not exist, the -p option will create both the /home/user and /home/user/new_dir directories.

-m (–mode)

The -m or –mode option allows you to specify the permissions for the new directory. For example, if you want to create a directory with read and execute permissions for all users, you would use the following command:

mkdir -m 755 directory_name

-v (–verbose)

The -v or –verbose option displays verbose output, which can be useful for debugging or understanding what the command is doing. For example, when using the -v option, the following command would display information about the new directory as it is being created:

mkdir -v directory_name

Examples of the mkdir Command in Action

Now that we have a basic understanding of the mkdir command and its options, let’s look at some examples of how to use the command in practice.

Creating a New Directory

To create a new directory, simply run the following command:

mkdir new_dir

This command will create a new directory named new_dir in your current working directory.

Creating Multiple Directories

To create multiple directories at once, simply specify multiple directory names in the same command. For example:

mkdir dir1 dir2 dir3

This command will create three new directories, dir1, dir2, and dir3, in your current working directory.

Creating Directories with Parent Directories

To create a directory along with its parent directories, use the -p option. For example:

mkdir -p /home/user/new