The mkdir command

Yaser Rahmati | یاسر رحمتی

The mkdir command in Linux/Unix is used to create a directory.

Syntax

mkdir [-m=mode] [-p] [-v] [-Z=context] directory [directory...]

Examples:

  • Make a directory named myfiles.

[root@academy tmp]# ls
ks-script-ggLlAt  yum.log
[root@academy tmp]# mkdir myfiles
[root@academy tmp]# ls -l
total 4
-rwx------. 1 root root 836 Dec 13 14:30 ks-script-ggLlAt
drwxr-xr-x. 2 root root   6 Dec 22 22:31 myfiles
-rw-------. 1 root root   0 Dec 13 14:23 yum.log
[root@academy tmp]#
  • Create a directory named myfiles at the home directory:

[root@academy tmp]# mkdir ~/myfiles
[root@academy tmp]# ls ~
anaconda-ks.cfg  myfiles
[root@academy tmp]#
  • Create the mydir directory, and set its file mode (-m) so that all users (a) may read (r), write (w), and execute (x) it.

[root@academy tmp]# ls
ks-script-ggLlAt  yum.log
[root@academy tmp]# mkdir -m a=rwx mydir
[root@academy tmp]# ls -l
total 4
-rwx------. 1 root root 836 Dec 13 14:30 ks-script-ggLlAt
drwxrwxrwx. 2 root root   6 Dec 22 22:36 mydir
-rw-------. 1 root root   0 Dec 13 14:23 yum.log
[root@academy tmp]#
  • Create the directory /home/test/src/python. If any of the parent directories /home, /home/test, or /home/test/src do not already exist, they are automatically created.

[root@academy tmp]# mkdir -p /home/test/src/python
[root@academy tmp]# ls /home/test/src
python
[root@academy tmp]#

Last updated