How to create a new directory/folder from the command line

The longer you spend developing websites, the more you’ll start working from the command line. It’s scary, I know. All that monospace type and no user interface! But we’re going to start small. In this post (and video) we’re going to take a look at an essential — and easy — command line operation: making a new directory.

Open command line

Start by opening your command line tool. On Mac OS use Terminal. You can find Mac Terminal by going to Applications > Utilities > Terminal.  On Windows you can use command prompt (Start > search > type: cmd).

Once your at the command line type pwd to see where you are. You’ll most likely be at your user directory, but pwd will tell you the directory path to where you are currently. Let’s say you’re at Users/timothy this would be essentially the same as having an OS window open to the timothy directory.

Now, type ls and hit enter to get a list of all the directories and files in the directory you’re currently in. Now let’s add a new directory.

Make the new directory

Type mkdir (for make directory) type in the name that you want to give to the new directory and hit enter. Now, when you ls again, you’ll see your new directory!!! Yeah!  Easy. You have a new directory just waiting for some files.

Now practice making new directories. Make two or three. Or three or four. It doesn’t matter, just play around. You can easily delete them later. You can even open up finder or windows and navigate to where you created the new directories. You’ll see them there. You can delete them from here or keep them if you’d like.

To recap, here are the commands we used:

ls – will list all the directories and files in the directory you’re currently in
mkdir filename – will create a new directory with the given filename

Watch the video tutorial below to get a better sense of how this works.

Go forth and command! your computer via the command line!

Other terminal command line tutorials:

How to make a new file in Mac Terminal Command Line

Leave a Reply

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