Introduction
This tutorial introduces the mkdir
command in Linux, focusing on its role in creating directories within the file system.
This tutorial introduces the mkdir
command in Linux, focusing on its role in creating directories within the file system.
The mkdir
command, short for "make directory" is used to create new directories or folders in a Linux terminal. It is a fundamental tool for organizing the file structure.
Let's start with a simple example. To create a directory named new_folder
in the current working directory, run the following mkdir
command and ls
command to display the current working files and directories:
Input:
mkdir /home/labex/project/new_folder
ls /home/labex/project
Output:
new_folder ## new folder has been created.
In this step, we'll cover the essential usage of the mkdir
command without exploring optional parameters or advanced features.
This tutorial extends the knowledge of the mkdir
command by introducing various options that can be used to customize its behavior.
mkdir [options] directory
-p
: It can be a path name. If some of the path's directories do not exist, this option will automatically create directories that do not exist. You may create multiple directories at a time.-m
: Set permissions of the newly created directory.-v
: Display detailed information while creating directories.The -p
option with mkdir
allows the creation of a directory and its parent directories if they do not exist. This is useful to create a nested directory structure without worrying about whether the parent directories are already present.
Input:
mkdir -p /home/labex/project/new_dir/sub_dir
ls /home/labex/project/new_dir
Output:
sub_dir
The -m
option with mkdir
allows you to specify the permissions of the newly created directory explicitly. You can use octal notation to define the permissions.
Input:
mkdir -m 755 /home/labex/project/permission_dir
ls -ld /home/labex/project/permission_dir
Output:
drwxr-xr-x 2 user group 4096 Dec 5 00:00 /home/labex/project/permission_dir
The -v
option with mkdir
enables verbose mode, which displays detailed information about the directories being created.
Input:
mkdir -v /home/labex/project/verbose_dir
Output:
mkdir: created directory '/home/labex/project/verbose_dir'
In summary, the mkdir
command is a versatile tool for creating directories in Linux. Whether you need to create nested directories, set specific permissions, or receive detailed feedback on the creation process, mkdir
provides essential functionality for file system organization.