How to Create Folders in Linux Using the mkdir Command
The mkdir command is an essential tool in Linux that allows me to effortlessly create folders in the file system. It’s like a magic wand that lets you organize your files and folders precisely the way you want. You can create folders within folders, nest them as deep as you want, and even control their permissions and security. Pretty cool, huh?
Whether you’re a tech wizard or just an everyday computer user, knowing how to use the mkdir command is a superpower that will help you keep your files in order and navigate through your Linux system with ease.
Here’s the basic syntax for using the mkdir command:
$ mkdir [OPTION] [DIRECTORY]
Contents
1. Get the Inside Scoop with the -v Option
mkdir -v
To see what the mkdir command is doing behind the scenes, use the -v (verbose) option.
For instance, when you use the mkdir -v newdir command in Linux, it will create a directory called “newdir,” and the -v (verbose) option will provide a description of the action. Here’s an example of what the output might look like:
mkdir: created directory ‘newdir’
2. Create multiple directories
mkdir [dir1] [dir2] [dir3]
To create multiple directories, simply list the directory names as command arguments, separated by spaces.
For example, if you run the command mkdir newdir1 newdir2 newdir3, it will create three new directories named newdir1, newdir2, and newdir3 in the current working directory. Usually, this command won’t produce any output if it’s successful.
If you use the ls command right after that, you might get something like this:
newdir1 newdir2 newdir3
Now let’s talk about setting directory permissions. To do this, we’ll use the mkdir command with the -m option.
For example, if you run mkdir -m 755 mydirectory, the new directory called mydirectory will have permissions set to 755. This means the owner will have read, write, and execute permissions, while the group and others will only have read and execute permissions.
Here’s a breakdown of the 755 permissions:
– 7 (owner): Read (4) + Write (2) + Execute (1) = 7
– 5 (group): Read (4) + Execute (1) = 5
Have you ever wondered how to create directories in the Linux command line? Well, I’m here to show you how. Let’s dive right in!
1. Create a Basic Directory
So, you want to create a new directory? It’s super easy. Just type the following command:
mkdir [dirname]
Replace “[dirname]” with the name you want to give your directory. It can be anything you like! Go ahead and give it a try.
2. Set Permissions for a Directory
Okay, let’s say you want to set some special permissions for your directory with SELinux. No worries, I’ve got you covered. Here’s what you need to do:
mkdir -Z [dirname]
This option lets you set default Security-Enhanced Linux rules for your directory right from the start. Pretty cool, right?
3. Create a Complete Directory Tree
Now, what if you want to create a whole bunch of directories at once? No problemo! Just use the following command:
mkdir -p [directory_tree]
With the -p option, you can create an entire directory structure effortlessly. Let me show you an example:
Let’s say you want to create a directory tree like this:
/path/to/your/directory/tree
All you have to do is run this command:
mkdir -p /path/to/your/directory/tree
The best part is, if any part of the path is missing, the command will create it for you. And if the directories already exist, no worries – no changes will be made.
So there you have it – three awesome ways to create directories using the Linux command line. Give them a try and start organizing your files like a pro!
Let’s explore more Linux commands:
Working with Directories | To remove a directory, just type rmdir. To navigate between directories, use cd. To find out which directory you are currently in, try pwd. When you want to see the contents of a directory, type exa or ls. |
Managing Files | To view the contents of a file, use the cat command. To copy a file, type cp. If you want to duplicate a file, try the dd command. For a more relaxed way to view a file, use less. Need to create an empty file? Just use touch. To create a link to a file, type ln. If you want to change the name of a file, use rename. For a quick preview of a file, try more. And if you want to see just the beginning of a file, type head. |
Manipulating the File System | To change the owner of a file or directory, use the chown command. mkfs is used to create a file system. And if you need to locate a file or directory, try locate. |
Networking | To check if a networked device is reachable, use the ping command. To get the contents of a URL, type curl or use wget to download a file from the web. If you want to configure network traffic, try iptables. And to diagnose network issues, use mtr. |
Searching and Processing Text | To search for files and directories, use find. To search for specific patterns within files, try grep. To manipulate or transform text, use sed. If you want to know what a command does, type whatis. For a faster and friendlier file search, try ripgrep or fd. And for concise command explanations, use tldr. |
System Information and Management | To view and manipulate the environment variables, use env. To see the command history, just type history. To monitor system resources, use top. To see who is currently logged in, use who. For a more detailed system monitoring tool, try htop or glances. And to see which files are open by processes, use lsof. |
Managing Users and Sessions | To multiplex several virtual terminals, try screen. To switch to another user, use su. To execute a command with superuser privileges, type sudo. And finally, to open a file or directory using the default application, just use open. |