Linux Commands: mkdir

Linux Commands: mkdir
Page content

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.

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.

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.

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.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname