Examples of the Unix mkdir command

Linux directory FAQ: How do I create (make) a directory on Linux or Unix?

The Unix/Linux mkdir command is used to create new Unix/Linux directories (sub-directories). Let's take a look at some mkdir command examples.

How to create one directory

This first example creates a new directory named tmp in your current directory:

mkdir tmp

This example assumes that you have the proper permissions to create a new sub-directory in your current working directory.

Linux mkdir example - How to create multiple directories at one time

This command creates three new sub-directories (memos, letters, and e-mail) in the current directory:

mkdir memos letters e-mail

Linux mkdir example - How to create several subdirectories at one time

Use the -p option of the mkdir command to create multiple levels of subdirectories with one command. This example creates the directory /home/joe/customer/acme/foo/bar, and makes all intermediate subdirectories, as needed:

mkdir -p /home/joe/customer/acme/foo/bar

As you can imagine, that's a lot easier than typing these equivalent commands:

cd /home/joe
mkdir customer

cd customer
mkdir acme

cd acme
mkdir foo

cd foo
mkdir bar

Linux mkdir command: "Permission denied" errors

As a final note, if you try to create a directory like this:

mkdir baz

and you get an error message like this:

mkdir: cannot create directory 'baz': Permission denied

as the message implies, you don't have permission to create this directory. You can use the ls command to figure out what permission you have in this directory.