Search⌘ K
AI Features

Creating Directories

Explore how to use the mkdir command to create directories and nested subdirectories efficiently without changing working directories. Understand options like -p for full path creation and avoiding errors, and learn to use brace expansion to quickly build complex directory structures from the command line.

The mkdir command

While we can create files in several ways, we’ll use the mkdir command to create directories. We learned how to use this command in Creating Directories in the introduction, but let’s dig in a little deeper by performing a common task: setting up a hierarchy of directories to store documents.

Let’s create a directory by the name of files:

$ mkdir files

Then, we use the ls command to verify the new directory exists:

$ ls -l
Terminal 1
Terminal
Loading...

Creating a subdirectory

Now, let’s create a directory inside of the files directory called photos. Based on what we’ve learned so far, our first instinct might be to do this by changing the working directory to the files directory and then issuing another mkdir command, but that’s not efficient. Instead, we specify the full ...