mkdir Command in Linux with Examples


This tutorial explains Linux “mkdir” command, options and its usage with examples.

“mkdir” command is used To make directories. This post describes “mkdir” command used in Linux along with usage examples and/or output.


Create the DIRECTORY(ies), if they do not already exist.

Here’s the listing of example usage of “mkdir” command:

1. To create directory(mkdir dir_name):

sanfoundry-> mkdir sample
sanfoundry-> ls

2. To create multiple directories(mkdir dir1_name di2_name dir3_name):

sanfoundry-> mkdir folder1 folder2 folder3
sanfoundry-> ls
folder1  folder2  folder3  sample

3. To control the permissions of new directories(mkdir -m permissions directory_name):

New directories are by default created with the read, write and execute (i.e., run as a program if a program) permissions enabled for the owner and group and the read and execute permissions enabled for other users. Thus, for example, to create a directory named sample for which all three types of permissions were enabled for all users use:

sanfoundry-> mkdir -m 777 sample
sanfoundry-> ls -l
total 4
drwxrwxrwx 2 himanshu himanshu 4096 Jul  7 19:31 sample

4. To create specified intermediate directories for a new directory if they do not already exist(mkdir -p path):

sanfoundry-> mkdir folder1/folder2/sample
mkdir: cannot create directory `folder1/folder2/sample': No such file or directory
sanfoundry-> mkdir -p folder1/folder2/sample
sanfoundry-> cd folder1/folder2/
sanfoundry-> ls

5. To show verbose message(mkdir -v directory_name):

sanfoundry-> mkdir -pv folder1/folder2/sample
mkdir: created directory `folder1'
mkdir: created directory `folder1/folder2'
mkdir: created directory `folder1/folder2/sample'
sanfoundry-> mkdir -v fol1 fol2 fol3
mkdir: created directory `fol1'
mkdir: created directory `fol2'
mkdir: created directory `fol3'

6. To know the version(mkdir –version):

sanfoundry-> mkdir --version
mkdir (GNU coreutils) 8.13
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

More options

"-Z" : set the SELinux security context of each created directory to CTX

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.