mkdir
(Make Directory): The mkdir
command in Linux is used to create new directories. You can create one or multiple directories at a time, specify the directory’s permissions, or even create parent directories if they don’t exist.
Basic Usage:
mkdir <directory_name>
: Creates a new directory with the specified name.- Example:
mkdir new_folder
Common Options:
mkdir -p <path/to/directory>
: Creates the specified directory and any necessary parent directories that don’t exist.- Example:
mkdir -p /home/user/projects/new_folder
mkdir -m <permissions> <directory_name>
: Creates the directory with specific permissions.- Example:
mkdir -m 755 new_folder
creates the directory withrwxr-xr-x
permissions.
Example:
mkdir my_directory
This command creates a directory named my_directory
in the current working directory.
Example with Parent Directories:
mkdir -p /home/user/documents/reports/2024
This command creates the entire path, including any missing parent directories (documents
, reports
, 2024
).
The mkdir
command is fundamental for organizing files and directories in a Linux environment, allowing you to build directory structures easily.