Linux mkdir command with examples

Linux mkdir with examples

In this article, we are going to see Linux mkdir command with examples.

mkdir command in Linux is used to create directories (also referred to as folders in some operating systems ). The mkdir command can create multiple directories at once. It is important to note that the user executing this command must have enough permissions to create a directory in the parent directory. If dont have permissions, we receive a ‘permission denied’ error.

Syntax:

mkdir [OPTION]... DIRECTORY...

1. Create a directory(folder) with the name ‘backup’ :

We can run either of below commands to create directory. -v prints a message for each created directory

[r2schools@master ~]$ mkdir backup [r2schools@master ~]$ mkdir -v backup mkdir: created directory 'backup'

2. The following command creates two directories within the current directory:

mkdir accounts sales

3. The -p option allows you to create parent directories as needed (if parent do not already exits). For example, you can create the following directory structure:

[root@master r2schools]# mkdir -p -v hr/USA/INDIA/BRAZIL/ mkdir: created directory 'hr' mkdir: created directory 'hr/USA' mkdir: created directory 'hr/USA/INDIA' mkdir: created directory 'hr/USA/INDIA/BRAZIL/'

Linux mkdir with examples

4. Create directory by specifying permissions.

[root@master r2schools]# mkdir -m 754 test