Create Directory in Linux with mkdir command.

Hi Techies! So let’s learn to “How to Create Directory in Linux with mkdir command”, “How to create folder in Linux with mkdir command”

It’s very simple to create a directory in linux from GUI mode, but from command line we have to use mkdir command.


How to create Directory or Folder in Linux with mkdir

So suppose we have to create a directory named as “tastethelinux” on the current directory.

Syntax:
$ mkdir <Name of the directory>
Create Directory in Linux
mkdir tastethelinux
$ mkdir tastethelinux 

So we have create a directory successfully in linux, same we have checked with ls command

let’s use -v option with mkdir command.

Syntax:
$ mkdir -{option} <Name of the directory>
Create Directory in Linux with -v option
-v option with mkdir command
$ mkdir -v tastethelinux

So -v option with mkdir is used for verbose means to print the message in linux.


How to create multiple folders in Linux with mkdir

So now we have to create a multiple directory with mkdir command, the name will be A1, B1, and C1.

Syntax:
$ mkdir <First Folder> <Second Folder> <...N folder>
$ mkdir A1 B1 C1

So what if we have to create a parent directory for tastethelinux directory then we have to use -p option.

Syntax:
$ mkdir -p <Parent Folder>/<Folder>
Create Directory in Linux
creating parent directory
$ mkdir -p Parent/tastethelinux

So first it will create a parent directory named as “Parent” and inside that it will create tastethelinux folder.


Set Permission while creating folders in Linux

So to set the permission while creating a directory we will use -m option. Now we have to give all permission to tla folder.

Syntax:
$ mkdir -m {permission} <Folder name>
creating a directory with a set of permissions
$ mkdir -m 777 tla

So there are read, write, and execute permissions on linux and “7” means that we are using read, write, and execute for the tla folder.

But when we create any directory by default value is 775 in linux.

Cheat-sheet of mkdir command
1. To Create a directory

Syntax: 
mkdir [directory_name] 

Example:  
mkdir tastethelinux 
2. To create a Multiple directory 

Syntax:  
mkdir [directory_name] [directory1_name] [directory3_name] 

Example:  
mkdir taste the linux  
3. To create a Multiple directories with {} 

Syntax: 
mkdir {[directory_name],[directory1_name],[directory3_name]} 

Example: 
mkdir {taste,example,linux} 
4. Create a parent directory 

Syntax: 
mkdir -p [directory_name]/[directory1_name]/[directory3_name] 

Example: 
mkdir -p taste/exam/pratice 
5. Print the message while creating a directory

Syntax: 
mkdir -v [directory_name] 

Example: 
mkdir -v taste 
6. set permission while creating a directory

Syntax:  
mkdir -m [permission] [directory_name] 

Example: 
mkdir -m 770 tastethelinux


Example to create a Directory or Folder.

Example to create a directory.

So the above image has practice folder and inside that there is many folder, we can see using tree command.

If you want to install tree command then use “apt install tree”

$ sudo apt install tree

So we have to create a directory, lets divide the same and do that step by step, you can refer for the solution below.

Step by Step to create a directory in linux.
practice
├── aa
│   ├── a1
│   └── a2
$ mkdir -vp practice/aa/a{1..2}
output: 
mkdir: created directory 'practice'
mkdir: created directory 'practice/aa'
mkdir: created directory 'practice/aa/a1'
mkdir: created directory 'practice/aa/a2'
├── bb
│   ├── b1
│   ├── b2
│   ├── b3
│   ├── b4
│   └── b5
$ mkdir -pv practice/bb/b{1..5}
output: 
mkdir: created directory 'practice/bb'
mkdir: created directory 'practice/bb/b1'
mkdir: created directory 'practice/bb/b2'
mkdir: created directory 'practice/bb/b3'
mkdir: created directory 'practice/bb/b4'
mkdir: created directory 'practice/bb/b5'
└── cc
$ mkdir -v practice/cc
output: 
mkdir: created directory 'practice/cc'
$ mkdir -vp practice/{aa/a{1..2},bb/b{1..5},cc}
output: 
mkdir: created directory 'practice'
mkdir: created directory 'practice/aa'
mkdir: created directory 'practice/aa/a1'
mkdir: created directory 'practice/aa/a2'
mkdir: created directory 'practice/bb'
mkdir: created directory 'practice/bb/b1'
mkdir: created directory 'practice/bb/b2'
mkdir: created directory 'practice/bb/b3'
mkdir: created directory 'practice/bb/b4'
mkdir: created directory 'practice/bb/b5'
mkdir: created directory 'practice/cc'

You can also create a same directory via using this command

$ mkdir -vp practice/aa/a{1..2} practice/bb/b{1..5}  practice/cc

Kindly refer the link so you can practice with us while learning the POST, it will take 40 to 50 seconds to boot the image.

Hope you like the Post and know how to create a directory or folder, Thanks to read the article, keep supporting us!


Give your valuable time