Skip to content
Home » Quickly Create Directories with the mkdir Command

Quickly Create Directories with the mkdir Command

  • Linux
  • 3 min read

The mkdir command is one of the most basic and fundamental commands in the Linux operating system. It is used to create new directories or folders in the file system. The mkdir command is very simple to use and is a staple in any Linux administrator’s toolkit. In this blog post, we will go over the basics of using the mkdir command.

Basic Usage

To create a new directory using the mkdir command, simply type mkdir followed by the name of the directory you want to create. For example, to create a directory called “example”, you would run the following command:

mkdir example

You can also create multiple directories at once by specifying multiple directory names after the mkdir command. For example:

mkdir dir1 dir2 dir3

This will create three directories, named dir1, dir2, and dir3, in the current working directory.

Advanced Usage

The mkdir command has several options that can be used to modify its behavior. Here are some of the most useful options:

p Option

The -p option allows you to create a directory and its parent/child directories in one command. For example, if you want to create the directory /path/to/itvraag, you can run the following command:

mkdir -p /path/to/itvraag

This will create the itvraag directory, as well as any parent directories that don’t already exist (in this case, /path/to). But take note that the path in this example is an absolute path, which will try to create the directories from the root and that requires elevated permissions. To create the directories inside an existing directory, use relative path by navigating to the directory and use a dot to indicate current directory.

mkdir -p ./path/to/itvraag

m Option

The -m option allows you to specify the permissions for the newly created directory. For example, to create a directory with the permissions set to 755, you can run the following command:

mkdir -m 755 example

v Option

The -v option makes the mkdir command verbose, meaning that it will display a message for each directory it creates. This can be useful for checking the progress of the command or for debugging purposes.

itvraag:~$ mkdir -vp ./path/to/itvraag
mkdir: created directory './path'
mkdir: created directory './path/to'
mkdir: created directory './path/to/itvraag'

Summary

The mkdir command is a fundamental tool in the Linux operating system for creating directories or folders. With its simple syntax and advanced options, it is a versatile and powerful tool for creating and managing directories. By understanding the basics and utilizing the advanced options and tips, you can become a power user and get the most out of this command.

Next Steps: To continue your learning journey with the mkdir command, you can try using it in combination with other commands, such as cd and ls, to navigate and manage your file system.

Challenge

Try creating a directory with the name -example using the mkdir command. Can you do it without any errors? This is a common issue that can be solved by using the -- option to specify the end of options for the mkdir command.

By mastering the mkdir command, you will have taken a big step towards becoming a proficient Linux user.

Leave a Reply

Your email address will not be published. Required fields are marked *

eight − six =