How to create a directory in Linux | Linux mkdir Command examples

How to create a directory in Linux | Linux mkdir Command examples

Crete a directory with mkdir command

Linux mkdir command is quite easy to use. using this command we create new directories in linux server or shell.

To create a directory, enter:

mkdir devops

Here it will create a directory called ‘devops’.

Crete a directory with permissions

Use the “-m”  to create the new directory with other than the default permissions. Here, create a directory with a permissions setting of “771″

mkdir -m771 devops

create multiple directories with different endings

You aren’t limited to just creating one directory at a time. Here, use a string-type wildcard to create several “devops_” directories with different endings.

mkdir devops{_01,_02,_03,_04}

create multiple levels of directories with one command

Use “-p” to create multiple levels of directories with one command. Directories can be created several deep by using the -p option which will then create multiple directories deep, note that the names are separated by a “/”.

mkdir -p /var/vmail/example.com/user/new

Create multiple directories in single command

The Linux command for making a single directory is mkdir. It is a simple command that allows you to create a directory by listing the name that you want. if we want to create multiple directories at the same time we can create by separating the directories that you would like to create with spaces.

mkdir oracle_db mysql_db postgresql_db

Add the “-v” it will show you the list of directories that it’s created.

mkdir -vp /var/vmail/example.com/user/new
mkdir: created directory '/var/vmail/example.com/user/new'

Leave a Reply

Your email address will not be published. Required fields are marked *