How to create directories with mkdir command in Linux

What mkdir command in linux

mkdir is short for make directory. New directory can be created in Linux using mkdir command in terminal mode. Different parameter can be passed when using mkdir command to achieve different result. In this guide we will discuss some of frequently used parameters to create directories with mkdir command in Linux terminal.

Use mkdir command

Most basic of mkdir is done by simply using mkdir with folder name.

mkdir foldername

Creating directories with mkdir command with directory name foldername.

Create multiple directories with single command

mkdir command can create multiple directories by single command. mkdir command with name of directories which need to create.

mkdir  abc xyz 123

Above command will create three directories abc, xyz and 123.

Another variation of mkdir command is where you create folder with subfolder in a single command.

mkdir –p abc/xyz/123

-p attributes stands for parent, this command creates parent directory with child directories in current working folder.

Create multiple parent directory

To create multiple child directories in one command use mkdir with -p switch. This allows creation of multiple parent child directory tree structure in one go.

mkdir -p test1/test2/test3

This will create a structure when test will be parent with child test2 and further test3 will be child of test2

Setting up permission of directory

[adsenseyu1]Knowledge of permission is necessary before setting up permissions for any directory.
Users to whom permissions for directories are given belong to three categories.

  • owner
  • group
  • all users

Categories of permission these users have: read, write and execute.
Numerical representation of permissions are 4 (read),2(write) and 1(execute). Add up numbers of each permission for each permission group will be used in command. For example, read and write permission will be :4+2=6

Now it if you want create a directory with all permission to owner, read and write to group and no permission to all users. You will use command

mkdir –m 760 xyz

mkdir with verbose

At time of execution of mkdir command, confirmation is not given by system about creation of directory. For this you can use mkdir command with verbose switch and get confirmation of directory creation.

mkdir -v directory_name