WebMasterCampus
WEB DEVELOPER Resources

Linux mkdir Command

Learn Linux mkdir Command with example


Linux mkdir Command

In Linux we can use “mkdir” command to create a new directory. mkdir stands for “make directory”.

To create a directory with mkdir, we have two possibility either use absolute path or relative path with directory’s name. Note: The absolute path or full path starts from the system root /, and the relative path starts from your current directory.

mkdir Command Syntax

>> mkdir [option] dir_name

mkdir <directoryName>

>> mkdir webmastercampus

# mkdir webmastercampus command will create a new directory with webmastercampus name.

mkdir Create Multiple Directories

>> mkdir {directory1,directory2, directory3, directory4}

# Create Multiple Directories with mkdir

mkdir Create Directories heirarchy with mkdir -p

>> mkdir -p webmastercampus/linux/commands

# mkdir -p will create multiple subdirectories. This makes sure that mkdir adds any missing parent directories in the process.

We can use ls -R to show the recursive directory tree.

mkdir Set rmx Permissions for new directory

>> mkdir –m777 DirM

# The mkdir command by default gives rwx permissions for the current user only.

# To give read, write, and execute permission for all users, add the -m option with the user 777 when creating a directory.

# To list all directories and show the permissions sets: -l

# The directory with rwx permissions for all users is highlighted. As you can see on the image above, two other directories by default have rwx permission for the owner, xr for the group and x for other users.

mkdir Create Directory with Verification

>> mkdir -v test

# use mkdir -v to see the details of the mkdir process.

mkdir Command in Linux (Documentation)


NAME
       mkdir - make directories

SYNOPSIS
       mkdir [OPTION]... DIRECTORY...

DESCRIPTION
       Create the DIRECTORY(ies), if they do not already exist.

       Mandatory arguments to long options are mandatory for short options too.

       -m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask

       -p, --parents
              no error if existing, make parent directories as needed

       -v, --verbose
              print a message for each created directory

       -Z     set SELinux security context of each created directory to the default type

       --context[=CTX]
              like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX

       --help display this help and exit

       --version
              output version information and exit
Created with love and passion.