Creating Directories in the Linux Shell
In the Linux shell, you can create directories using the mkdir
(make directory) command. This command allows you to create new directories at the desired location within the file system hierarchy.
Basic Usage of the mkdir
Command
The basic syntax for the mkdir
command is:
mkdir [options] <directory_name>
Here, [options]
represents any optional flags or parameters you can use with the mkdir
command, and <directory_name>
is the name of the directory you want to create.
For example, to create a new directory named project
in the current working directory, you can use the following command:
mkdir project
Creating Directories with Absolute and Relative Paths
You can also create directories using absolute or relative paths. For example, to create a new directory named labex
in the /home
directory, you can use the following command:
mkdir /home/labex
Alternatively, if your current working directory is /home
, you can create the same directory using a relative path:
mkdir labex
Creating Multiple Directories at Once
The mkdir
command also allows you to create multiple directories at once. To do this, simply provide the names of the directories separated by spaces:
mkdir project1 project2 project3
This will create three directories: project1
, project2
, and project3
.
If you need to create a directory within a directory that doesn't exist yet, you can use the -p
(parent) option. This will create the necessary intermediate directories as well.
For example, to create the directory /home/labex/project
when the /home/labex
directory doesn't exist yet, you can use the following command:
mkdir -p /home/labex/project
By understanding the basic usage of the mkdir
command, you can efficiently create directories in your Linux environment to organize your files and projects.