Hello admins, Jack Wallen here with a Linux 101-level tip. This time around we’re going to learn how to create a directory from the command line. I know, it sounds incredibly basic. It is, but it’s also a skill you’re going to need to know. Why? Because at some point you’re going to be faced with administering a Linux server without a GUI.

When that happens, you’ll be glad you know how to create a directory from the CLI.

But how do you do it? It’s actually incredibly simple.

SEE: Kubernetes security guide (free PDF) (TechRepublic)

Once you’ve logged into your server, create a directory named test in your home directory with the command:

mkdir ~/test

It’s that simple, but let’s dig a bit deeper.

Say you want to create the directory test within project in your home directory, but project had yet to be created. If you issue the command mkdir ~/project/test, you’ll see the error that test cannot be created because there’s no such file or directory named project.

In order to make this work, you have to add the -p option as in:

 mkdir -p ~/project/test

The -p option stands for parents, which instructs mkdir to create the parent(s) directory (or directories) as needed.

What if you need to create a number of directories? Say you have ~/projects created and you want to create directories for Java, JavaScript, and dotNet? Change into projects with the command:

cd ~/projects 

Then issue the command:

mkdir java javascript dotNet 

Or, you could do the same thing from outside the projects directory with a command like:

mkdir ~/projects/{java,javascript,dotNet}

You can even set the permissions of a directory with the mkdir command.

If you want to create the folder data, but limit all access permissions to the owner, do that with the command:

mkdir -m=700 ~/data

Or, if you wanted to give user and group full permission, but leave out other, you could issue the command:

mkdir -m=770 ~/data

And that’s all there is to creating directories in Linux with the mkdir command. Your dream of becoming a Linux admin is a bit closer to coming true.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.


Image: Jack Wallen

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays