Linux 101: How to create a directory from the command line
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:
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:
The -p option stands for parents, which instructs mkdir to create the parent(s) directory (or directories) as needed.
Then issue the command:
Or, you could do the same thing from outside the projects directory with a command like:
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:
Or, if you wanted to give user and group full permission, but leave out other, you could issue the command:
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.