mkdir is used to create directories. The name mkdir is short for “make directory”.
Basic Syntax
mkdir [options] target
Here, target specifies the name of the directory you want to create. If no directory name is specified, mkdir displays an error message.
Commonly Used Options
-
-p: This creates parent directories if they don’t exist. -
-m: This sets the permissions of the new directory. -
-v: This displays a message for each directory that is created.
Useful Examples
-
mkdir mydir: This creates a new directory namedmydirin the current working directory. -
mkdir /home/user/mydir: This creates a new directory namedmydirin the/home/userdirectory. -
mkdir -p mydir/newdir: This creates a new directory namednewdirinside themydirdirectory. If themydirdirectory does not exist, it will be created. -
mkdir -m 755 mydir: This creates a new directory namedmydirwith the permissions set torwxr-xr-x. -
mkdir -v mydir: This creates a new directory namedmydirand displays a message confirming that the directory was created.
Leave a Reply