Pin Me

Linux Command Line: mkdir

written by: jlwallen•edited by: J. F. Amprimoz•updated: 7/4/2011

Serious Linux administration often begins and ends with the command line. And one command you will find indispensable when working with the Linux file hierarchy is the "mkdir" command. This entry to the Linux Command Line series will introduce you to "mkdir".

  • slide 1 of 4

    History

    The Linux mkdir command has its roots in early versions of UNIX, but there were large differences from where it began to where it is now. When mkdir began only the root user could create directories within the file structure. That held true even for user directories. Things have changed and now anyone can create a subdirectory so long as they have permission to work within the directory the subdirectory is to be created. In other words if user mary wants to create a misc directory within /home/mary/ she can. However, if user mary wants to create a directory within /etc she can't unless she has the root user password. Of course the root user can create subdirectories anywhere in the Linux file structure.

  • slide 2 of 4

    Basic Usage

    The mkdir command is very easy to use. We will stick with our example above and show how user mary can create the directory misc~/~/ within her home directory. The first thing that will have to be done is to open up a terminal window (such as aterm, gnome-terminal, or konsole). When the terminal window opens the bash prompt will be at the ~/ directory (that is the home directory of the user, or in this case /home/mary). At the bash prompt user mary would enter the command mkdir misc and the directory /home/mary/misc will be created.

    But let's say user mary is in her home directory (/home/mary) and wants to create a new subdirectory within the newly created /home/mary/misc directory called dec08. The user mary doesn't have to change into /home/mary/misc but can just issue the command mkdir /home/mary/misc/dec08 in order to create the new directory. In other words, as long as the user has permission to create the subdirectory, the new directory can be created from anywhere within the file structure.

  • slide 3 of 4

    More Advanced Usage

    Let's say you want to create both /home/mary/misc and /home/mary/misc/dec08 at the same time. This is possible with the help of the -p argument. To do this you would issue the command mkdir -p /home/mary/misc/dec08 and both new directories will be created. You can also add the -v argument which will list the newly created directories as they are created. This addition will look like mkdir -pv /home/misc/misc/dec08.

  • slide 4 of 4

    Final Thoughts

    Linux system administration would eventually become difficult (if not impossible) without the help of the mkdir command. Although mkdir is a very simple command, it is wise to familiarize yourself with this must-have tool for your command line toolkit.