Creating a directory is a common task while working with a Linux terminal. You create directories from time to time and transfer data across multiple directories. Before using a Linux command , you must know all the flags and options available for that command.
Also, you should be aware of the utility of the command so that you can fully leverage it to become more efficient at work. mkdir is shorthand for “Make Directory” in Linux. This command basically creates a new subdirectory in the specified directory. In this article, we will be discussing the mkdir command in Linux, the options/flags available for this command, and some examples of its usage. So, let’s begin!
What are Flags?
Flags in Linux are used to modify the default behavior of the command. There are many flags associated with each command. Flags are also known as options in Linux.
What is mkdir Command in Linux?
This is an effective command that lets you create one or more directories (or folders) in the specified directory. The user creating the directory must have required writing permissions in order to create a directory to avoid the “Permission Denied” error. The syntax for mkdir command is shown below:
mkdir [options] [directories]
To learn more commands in Linux, you can purchase the course from here.
How to Use the mkdir Command in Linux with Various Options?
The below command will display all the available options and provide other assistance related to the mkdir command:
- Using the -v option with the mkdir command will notify you of the directory creation.
mkdir -v <directory_name>
In the above example, we have created a directory named “test” and we got the message of successful directory creation.
- Using the -m option with the mkdir command allows you to set the file modes and permissions associated with the directory for all the users. The modes can be read, write or execute. The syntax for this is:
mkdir -m <mode> <directory>
Now, Let’s create a new directory and give read and write permissions to all users.
- [mkdir -p flag] The -p option tells the command to create parent directories if they're needed. It does not create a new directory if one already exists. The syntax is
mkdir -p <directories>
In this article, we discussed How to use mkdir command in Linux. A directory is just a set of files. Directories are created to keep the same kind of files at the same place or simply to organize files in a better way. You can create one or more directories at the same time using the mkdir command in the Linux terminal.
The command comes with various options that help you to modify the default behavior of the command. You can also set permissions for all the users while creating a directory. Besides, this command also allows you to get the confirmation message of the directory created. It's a handy Linux utility for a developer who uses a command-line interface for creating and working with directories. Hopefully, you will now be able to use the mkdir command to your advantage.
People are also reading: