• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

mkdir Command in Linux with Examples

{{postValue.id}}

mkdir Command

mkdir command is used to create a new directory in Linux machine. This command is default shell command in Linux.

Syntax

mkdir [option] directory name

Make directory in current working directory

mkdir command is used to make new directory in current working directory.

Output

[user1@Linuxhelp]$ mkdir redhat 
[user1@Linuxhelp]$ pwd 
/home/user1/
[user1@Linuxhelp]$ ls -l 
total 4
drwxr-xr-x. 2 root root 4096 Jan 22 15:48 redhat

Make two or more directory in single command

mkdir command is used to make two or more directories using a single command.

Example

[user1@Linuxhelp]$ mkdir red1 red2


Output

[user1@Linuxhelp]$ ls -l 
total 12
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red1
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red2

Make Collaborative Directory

mkdir command is used to make a nested directory.

Output

[user1@Linuxhelp]$ mkdir -p red3/red4/red5
[user1@Linuxhelp]$ ls -l 
total 16
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red1
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red2
drwxr-xr-x. 3 root root 4096 Jan 22 16:26 red3
drwxr-xr-x. 2 root root 4096 Jan 22 15:48 redhat
[user1@Linuxhelp]$ cd red3
[user1@Linuxhelp]$ ls -l 
total 4
drwxr-xr-x. 3 root root 4096 Jan 22 16:26 red4
[user1@Linuxhelp]$ cd red4
[user1@Linuxhelp]$ ls -l 
total 4
drwxr-xr-x. 2 root root 4096 Jan 22 16:26 red5

Make Directory with Confirm Message

mkdir command will make new directory with confirm message

Output

[user1@Linuxhelp]$ mkdir -v red4 
mkdir: created directory `red4' 
[user1@Linuxhelp]$ ls -l 
total 20
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red1
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red2
drwxr-xr-x. 3 root root 4096 Jan 22 16:26 red3
drwxr-xr-x. 2 root root 4096 Jan 22 16:41 red4
drwxr-xr-x. 2 root root 4096 Jan 22 15:48 redhat

Make directory with file permission

mkdir command will make directory with 444 permission

Output

[user1@Linuxhelp]$ mkdir -m 444 red5
[user1@Linuxhelp]$ ls -l 
total 24
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red1
drwxr-xr-x. 2 root root 4096 Jan 22 16:07 red2
drwxr-xr-x. 3 root root 4096 Jan 22 16:26 red3
drwxr-xr-x. 2 root root 4096 Jan 22 16:41 red4
dr--r--r--. 2 root root 4096 Jan 22 16:47 red5
drwxr-xr-x. 2 root root 4096 Jan 22 15:48 redhat

Make directory in the specified path from the current directory

Here, the new directory is created from the current location to the desired location.

Output

[user1@linuxhelp Desktop]$ mkdir /home/user1/Desktop/redhat7
[user1@linuxhelp Desktop]$ ls &ndash l 
total 24
drwxr-xr-x. 2 user1 user1 4096 Jan 22 16:07 redhat1
drwxr-xr-x. 2 user1 user1 4096 Jan 22 16:07 redhat2
drwxr-xr-x. 3 user1 user1 4096 Jan 22 16:26 redhat3
drwxr-xr-x. 2 user1 user1 4096 Jan 22 15:48 redhat6
dr--r--r--. 2 user1 user1 4096 Jan 22 15:53 redhat8
drwxr-xr-x. 2 user1 user1 4096 Jan 22 15:48 redhat7

Tags:
jackson
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How do I create multiple inherited directory without any parent directory using the "mkdir" command?

A

You can use the option of "-p" with "mkdir" command to create multiple inherited directory without any parent directory using the "mkdir" command. For Synta: "mkdir -p /dir1/dir2/dir3/dir4/".

Q

How to print the message of an action to be while executing the "mkdir" command?

A

You can use the option of "-v" with "mkdir" command to print the message of an action to be while executing the "mkdir" command. For Ex: "mkdir -v /dir/".

Q

How Do I set the permission of the directory while creation process itself?

A

Use the option of "-m" with mkdir command to set the permission of the directory while creation process itself. For Syntax: "mkdir -m 775 /dir/".

Q

How Do I know the entire information and options to be available for "mkdir" command?

A

You can use the option of "--help" and "man" page of "mkdir" command to know the entire information and options to be available for "mkdir" command. For Ex: "mkdir --help" (or) "man mkdir".

Q

How to set SELinux context for any directory while creating itself using the "mkdir" command?

A

You can use the option of "-Z" with "mkdir" command to set SELinux context for any directory while creating itself using the "mkdir" command. mkdir -Z selinux_label /dir/".

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.