Make Directory using mkdir Command in Linux Tutorial for Beginners

Making or Creating a Directory (Folder)

mkdir Command in Linux



In detail, we can say the meaning of “mkdir” is to Make Directory.   When we need to make or create a new folder or directory at a certain location.

we have to use mkdir command followed by the name of the folder and location, It may an absolute path or relative path as applicable.

If you are interested in learning Ethical Hacking, you can visit at – How to use Rockyou Wordlist in Kali Linux

Practical Use of mkdir Command

mkdir dataA folder called “data” will be created. Very simple use of mkdir command to create a folder “data” in the present working directory. you can use pwd command to know present working directory.
mkdir /home/ajay/dataA folder “data” will be created in the path location /home/ajay.  The absolute path may be used when our present working directory is in different location.
mkdir mohit sharmaTwo folders “mohit” and “sharma” will be created in the present working directory.  Normally, a space character is not acceptable.
mkdir “mohit sharma”A folder “mohit sharma” will be created.  The name should be in the double inverted quote when the name of the folder contains a space character.
mkdir dir1 dir2 dir3 dir4 …A number of folders can be created with a single line command giving spaces between all folder names.
mkdir /home/dir1 /tmp/dir2 …When more than one directory to be created in other than present working directory, a relative path should be used for each file name with horizontal spaces.
mkdir -p shopThis command will also act as similar to command “mkdir”.  Means, a folder “shop” will be created simply.
mkdir -p office/file/photo/oldParent directory “office” will be created. And a folder “file” will be created inside the “Office” folder.  Also, a folder “photo” in the folder “file” and again a folder “old” in the folder “photo” will be created.   office (Parent folder) – file – photo – old
mkdir .bhagatA hidden directory called “bhagat” will be created, which will not be shown on applying only “ls” command. On applying “ls -a” command, the directory “.bhagat” will be shown.

Most used options with mkdir command

mkdir -m

By default, ‘rwx rwx r-x’ (digit 775) permission applied for newly created folders with command “mkdir”.  But, if we want to set custom permission of read, write and execute for all kind users as well as groups, use of command “mkdir -m777” set to ‘rwx rwx rwx’ permission. 

To see the permission label, we must use the command “stat foldername”.

Overview of Permissions in Linux

Let’s know, The type of permissions of folders and files, It is very important to learn deeply. 

Basically, three digits after “-m” denotes owner, group and user of the concerned folder or file respectively.  And the numbers starting from zero to 7 denote the range of permission. 

The fact is well explained in the undermentioned table.

Digit NumberOwner StatusPermission Range
1st DigitOwner of FolderNo permissionExecute onlyWrite onlyWrite & Execute onlyRead onlyRead & Execute onlyRead & Write onlyRead, Write & Execute
2nd DigitGroup in LinuxNo permissionExecute onlyWrite onlyWrite & Execute onlyRead onlyRead & Execute onlyRead & Write onlyRead, Write & Execute
3 DigitOther UsersNo permissionExecute onlyWrite onlyWrite & Execute onlyRead onlyRead & Execute onlyRead & Write onlyRead, Write & Execute

Examples :-

  1. mkdir -m714 delhi


     If we use command mkdir -m714 delhi, it means a folder called “delhi” will be created with permission to “read, write and execute” for the owner of the folder, permission to “execute only” for the group and permission to “read-only” for other users.

  1. If we have to create folder called “Nagpur” with accessing permission to “write and execute only” for owner (creator), no permission for the group and permission to “read and execute only” for other users, then the command will be as under

Ans.                    Mkdir -m305 Nagpur

mkdir -p

Generally, if we use mkdir for creating a folder already exist, then an error will be shown as “mkdir: cannot create directory “foldername”: File exists”.  But if we use -p option with mkdir command, the error message will not be shown even the folder you want to create, already exists.  Also, the files and other sub-folders exists in the folder already created earlier, will not be removed.

linux command tutorial mkdir p
mkdir -v

When we need a confirmation from the system that the folder with exact name has been created, we can use this command.  This will help us to double confirm about the name of folder created, is correct.  This command is more useful when the name of folder is very critical and we need to re-check that the folder with correct name is created.  A confirmation under the following statement will be given by the system regarding creating the folder.

linux command tutorial mkdir v
mkdir -Z (capital Z)

Use of this command will also create a folder in similar way as “mkdir”.

mkdir –help

This command will render us the list of all accessible commands of “mkdir”.  After reading the note, we can better understand the command “mkdir” and its relevant uses.

linux command tutorial mkdir help
mkdir –version

This command will display the version history of command “mkdir”.

linux command tutorial mkdir version

Special Tips: Combine of multiple options

We can use -v and -p with a same line of command to create folder with sub-folders and also get confirmation from the system for each folder and sub folders.

linux command tutorial mkdir p & v

If Appreciate My Work, You should consider: