Creating Directories

Window

Now that we've covered listing and changing directories, let's learn how to add new directories.

We can do this in the GUI in a super simple way. Just right-click New, then Folder, and bam, you have a new folder. 🗂️

Creating Directories in the CLI 💻

Now what if we wanted to do this in the CLI? In PowerShell, the command to make a new directory is called mkdir or make directory. Let's make a new directory called my_cool_folder, there it is. That was easy. 😎

Handling Spaces in Directory Names ⚠️

What if we wanted to use spaces in our folder name instead of underscores? What do you think would happen if I did this instead? Mkdir my cool folder, that's an error. Mkdir is trying to interpret cool and folder as other parameters to the mkdir command, it doesn't understand those words are valid parameters.

Turns out that our shell doesn't interpret spaces the way we do. We need to tell it explicitly that this folder name is one single thing. We can do this in a variety of ways. We can surround the name with quotes, like mkdir "my cool folder", or we can escape the space by using the back tick character mkdir my\ cool\ folder.

Escaping characters is a pretty common concept when dealing with code. It means that the next character after the back tick should be treated literally. In our example, escaping the space tells the shell that the space after the back tick is part of our filename. While the back tick is the escape character in PowerShell, other shells and programming languages may use another character as an escape character. 🐧

Linux Creating Directories in Bash 🐧

Making a New Directory with Spaces 🗂️

In Bash, the command to make a new directory is the same as in Windows. Let's make a new directory called my cool folder with the mkdir or make directory command. Now we can verify my cool folder is in our desktop. 💻

Escaping Spaces in Bash 🔤

Instead of using backticks like in Windows to escape a character, in Bash, you can use a backslash. mkdir my\ cool\ folder

Similar to Windows, you can also use quotes to encompass an entire file name. mkdir "my cool folder"

Creating Directories with Spaces in Linux 🐧

How do you think you would make a directory called my cool folder in Linux with spaces? 🤔

mkdir my\ cool\ folder Oh, there it is. 🎉

Or mkdir "my cool folder" works as well. 🙌

If you guessed this, you're right. If you guess wrong, that's okay. Just re-watch this video so you can get a better grasp of how we came to this conclusion. 🎥

Last updated