mkdir
The mkdir
command, short for „make directory“, is used to create new directories in a Linux system. This command is essential for any Linux user who wants to organize their files and folders in a structured manner.
What’s it for?
The primary use of mkdir
is to create new directories where you can store your files and subdirectories. This helps keep your file system tidy, making it easier to find specific files and reducing the risk of data loss due to misplacement or overwriting.
Syntax
The basic syntax for using mkdir
is:
bash
mkdir [options] directory_name
Where [options]
can include -p
(create parent directories if they do not exist), --help
(display help information and exit), and others. The directory_name
is the name you give to your new directory.
Examples
-
To create a new directory named „Documents“ in your current working directory:
bash
mkdir Documents
-
To create a new directory named „My Project“ with its parent directories if they do not exist:
bash
mkdir -p My\ Project
Special Hacks
-
mkdir with multiple directories at once: While you can manually
cd
into each parent directory before making the actual one, using-p
option makes it more efficient.
bash
mkdir -p path/to/new/directory
-
Using mkdir in a script or automation pipeline: In scripts or automated tasks where directory creation is part of the setup process,
mkdir
can be used directly without interactive prompts, ensuring directories are created as expected.
Level of Experience
This command is suitable for beginners to intermediate users. Understanding how to use mkdir
effectively is a foundational skill in using Linux and managing your files and directories efficiently. It’s recommended that new users learn this early on, while advanced users will appreciate the flexibility it provides in scripts and automation tasks.