How to use the Linux mkdir command to create new directories

With the Linux command mkdir you can create one or more folders in your current directory. You can also use it to set up complex folder hierarchies.

What is the Linux mkdir command?

The Linux mkdir command is used in Linux to create a new directory. You can also do this with a graphical file manager but if you work with commands often, this one will become very important. Linux mkdir is one of the most important and widely used commands for all common Linux distributions, as well as Ubuntu. mkdir is a shortened form of ‘Make directory’.

How does the mkdir command work?

To create a new directory using mkdir, it’s important that you check, first and foremost, that you’re in the correct directory. The command will make a new directory where you are located as standard. If you want to add the corresponding folder to another location, use the Linux cd command to switch to it. You can then use mkdir to create your new directory. Linux mkdir enables you to create multiple folders or a hierarchy in addition to subfolders. How exactly is set out below.

What does the mkdir syntax look like?

The syntax of the command is always the same and looks as follows:

$ mkdir [Option] Directory name
shell

mkdir is the actual command and is followed by different options. The directory name is the name of the folder which you want to create. Pay attention not to make any typos so that you can find and open the directory later.

What options does the mkdir command have?

You have three options in mkdir. This is how they work:

  • -m or –mode: With this option you can set certain access rights to the new directory. These are specified after the parameter.
  • -p or –parents: You can use this option to create the directory or directories if they don’t yet exist. If a directory of the same name already exists in the same location, you’ll receive an error message.
  • -v or –verbose: You can use this option to see what mkdir is currently doing from the command bar. In most cases, this option is used alongside -p-.

Examples of a mkdir command

So that you have a better understanding of Linux mkdir, here are a few simple examples of how it works.

$ mkdir Contacts
shell

Use this to create a new folder called ‘Contacts’ in your current directory.

$ mkdir Contacts Material
shell

Use this command to create the folders ‘Contacts’ and ‘Material’ of the same hierarchical value in your current directory.

$ mkdir -p Contacts / {Customers, Suppliers} / {Orders, Invoices}
shell

This command will create a directory called ‘Contacts’ in your current folder which has the following hierarchy:

Contacts

  • Customers
    • Orders
    • Invoices
  • Suppliers
    • Orders
    • Invoices
In order to provide you with the best online experience this website uses cookies. By using our website, you agree to our use of cookies. More Info.
Manage cookies