04. mkdir command - muneeb-mbytes/linux_course GitHub Wiki
mkdir command
Figure.1 represents the mkdir command variations.
Figure.1. Representation of mkdir command variation
Directory
A directory is a file whose job is to store the file. It is a type of folder in CLI. Home directory - The directory in which you find yourself when you first login is called your home directory. You can go into your home directory anytime using the following command − $cd ~
"~" indicates the home directory.
mkdir command cheat sheet
S.No. | mkdir different options | description |
---|---|---|
1 | mkdir dir_name | Use to created single directory |
2 | mkdir dir_name1 dir_name2 dir_name | Use to create multiple directory |
3 | mkdir -p dir_name1/dir_name2/dir_name3 | Use to create the parent directory and sub directory |
4 | mkdir -m 777 dir_name | To give the rwx permission to the directory |
5 | mkdir -v dir_name | Use to get the confirmation of directory created or not as output |
6 | mkdir --version | Give the license information |
7 | mkdir --help | Give more information about mkdir command |
mkdir variations:
MKDIR commands are the basic commands to create the directory. Syntax - mkdir [option] directory_name "mkdir" stands for make directory. Key point- In Linux, the commands and options are case-sensitive.
Commands for creating the directory
mkdir directory_name
This command is used simply to create a directory in Linux.
Figure.2 shows directory is created .
Figure.2. Usage of mkdir single dir creation command
GIF.1 shows the whole process from sourcing scripting file till the output.
GIF.1. mkdir single dir GIF
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_single_dir.csh
mkdir dir_name1 dir_name2 dir_name3
This command is used to create multiple directories with the use of a single command.
Figure.3 shows two directories is created .
Figure.3. Usage of mkdir multiple dir creation command
GIF.2 shows the whole process from sourcing scripting file till the output.
GIF.2.mkdir multiple dir GIF
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_multiple_dir.csh
mkdir -p dir_name1/dir_name2/dir_name3
Flag "p" stands for parent . This flag which enables the command to create parent directories as necessary.(It means , command is use to create parent directories preferably .)
This command is used to create sub-directories in a parent directory. Here, the dir_name1 is the parent directory inside it dir_name2 sub-directory is created and similarly dir_name3 is created inside the dir_name2.
This command is for creating multiple directories but with a hierarchy of parent and child and sub-child.
If the directory is already created , while executing this command it will not show any error. It will execute successfully.
syntax : mkdir -p parent_dir/child_dir/sub-child_dir
In figure.4 shows that mangalore is parent_dir, udupi is child-dir and manipal is sub-child dir .
Figure.4. Usage of mkdir -p parent_child_sub-child
GIF.3 shows the whole process from sourcing scripting file till the output.
GIF.3.mkdir -p parent_child_sub-child GIF
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_par_ch_subch.csh
mkdir -p dir1 dir2/dir3
By using this command can create multiple directories with hierarchy of two parent directories are created and one child directory for second parent and so on.
syntax : mkdir -p parent1 parent2/child1
Figure.5 shows two parent and one child directory is created .
Figure.5. Usage of mkdir -p parent1 parent2/child1 command
GIF.4 shows the whole process from sourcing scripting file till the output.
GIF.4.mkdir -p parent1 parent2/child1 GIF
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_par_ch.csh
mkdir –m 777 DirM
This command is used to create a directory DirM with [rwx permissions] The mkdir command by default gives rwx permissions for the current user only. To add read, write, and execute permission for all users, add the -m option with the user 777 when creating a directory. To get the more information about permission modes ,refer to chmod commands.
Figure.6 shows directory is created with read, write and execute permission .
Figure.6. Usage of mkdir -777 command
GIF.5 shows the whole process from sourcing scripting file till the output.
GIF.5.mkdir -m 777 GIF
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_777.csh
mkdir –v dir_name(s)
This command gives the feedback of the command. To verify whether the directory is created or not, no need to use the "ls" command after using this command. It will give the output after processing the command.
Figure.7 shows directory is created and receive feedback from CLI .
Figure.7. Usage of mkdir -v command
GIF.6 shows the whole process from sourcing scripting file till the output.
GIF.6.mkdir -v GIF
**Github lab link: ** https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/mkdir_commands/mkdir_verbose.csh
mkdir --version
This command is use to display the version number with some information regarding the license and exits .
mkdir --help
This command display the help related information of the mkdir command.
To learn clear command: https://github.com/muneeb-mbytes/linux_course/wiki/05.-clear_command