mkdir Command in Linux with Examples
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
Comments ( 0 )
No comments available