Linux Terminal Command: mkdir
The mkdir command is an essential tool in Foundations & Navigation. In this tutorial, we will explore what mkdir does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The mkdir command creates one or more directories at the specified paths, provided the parent directories exist and the user has write permissions.
Common Options & Syntax
mkdir [options] [arguments]
Here are the most common flags used with mkdir:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
mkdir new_folder
What it does: Creates a directory named ’new_folder’ in the current working directory.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
mkdir -p project/src/{components,utils,tests}
What it does: Recursively creates parent directories if they do not exist (-p) and uses brace expansion to initialize subfolders components, utils, and tests instantly.
⚙️ Warning & Common Pitfalls
[!WARNING] Trying to create a directory in a path where parent folders do not exist will fail unless you pass the
-p(parents) flag.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: