Linux offers a multitude of commands to facilitate various operations for users,
one of which is
mkdir — a shorthand for "Make Directory." This command-line
utility allows users to create new directories (or folders) in the file system.
In this article, we will dive deep into the
mkdir command, exploring its
syntax, options, and examples.
The basic syntax of the
mkdir command is as follows:
mkdir [OPTIONS] DIRECTORY_NAMES
OPTIONSare the optional flags that modify the behavior of the
DIRECTORY_NAMESspecify the name(s) of the directory or directories to be created.
Creating a new directory is simple. Open a terminal window and type:
This will create a directory named
new_directory in the current working
|Creates parent directories as needed. If the specified directories exist, no error is returned.|
|Sets the permission mode for the newly created directories. The mode is specified in octal numbers.|
|Prints a message to the terminal for each directory that is created, useful for debugging.|
|N/A||Displays a help message detailing the options and usage of the |
|N/A||Outputs the version information of the |
mkdir command offers several options that can be used to customize the
behavior of the command.
This option allows you to create parent directories as needed. If you specify a path that includes non-existent directories, this flag will create those parent directories for you.
mkdir -p dir1/dir2/dir3
In the above example, if
dir2 don't exist,
mkdir will create them
Sets the permission mode for the new directory. It's expressed in octal numbers.
mkdir -m 700 private_directory
Here, only the owner of
private_directory will have read, write, and execute
When this option is used,
mkdir will print a message for each directory that
mkdir --verbose new_directory
mkdir: created directory 'new_directory'
This is the shorthand for
mkdir -v another_directory
Displays the help menu for the
Displays the version information of the
You can combine multiple options to perform complex tasks.
mkdir -pv -m 755 dir1/dir2/dir3
In this example,
-p ensures that parent directories are created if they don't
-v makes the operation verbose, and
-m 755 sets read, write, and
execute permissions for the owner, and read and execute permissions for the
group and others.
Here are some practical examples:
Creating a single directory
Creating multiple directories
mkdir dir1 dir2 dir3
Creating nested directories
mkdir -p parent/child/grandchild
Creating a directory with specific permissions
mkdir -m 700 secure_dir
Creating multiple directories with verbose output
mkdir -v dir1 dir2 dir3
mkdir command in Linux is a powerful tool for creating directories. It
comes with various options that allow you to create multiple directories, set
permissions, and even create parent directories as needed. Once you understand
how to use
mkdir and its options effectively, managing your file system
becomes a much more streamlined process.
Level Up Your TypeScript And Object Oriented Programming Skills. The only complete TypeScript course on the marketplace you building TypeScript apps like a PRO.SEE COURSE DETAILS
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for ssoftware developers.