mkdir Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The mkdir command in Linux is used to create new directories. It stands for 'make directory' and is a fundamental command for managing the file system hierarchy in Linux.
Linux mkdir Command Syntax
The syntax for the mkdir command is as follows:
Where:
- OPTIONS: These are the flags that can be used to modify the behavior of the mkdir command.
- DIRECTORY: The name of the new directory or directories to be created.
mkdir Command Options:
- -m, --mode=MODE: Sets the file mode (permissions) for the new directory.
- -p, --parents: Creates parent directories as needed. If the directory already exists, it does not return an error.
- -v, --verbose: Provides more detailed output of the command execution.
- --help: Displays help information for the command.
Example Usages
-
Create a single directory.:
Explanation: This command creates a new directory named 'test_directory' in the current working directory.
-
Create multiple directories.:
Explanation: This command creates three new directories (dir1, dir2, and dir3) in the current working directory.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
Always check if a directory with the same name already exists before creating a new one, to avoid overwriting or errors.
-
Use the -p option to create a complete directory hierarchy in one command.
Advanced Use Cases of mkdir Command in Linux
-
Create a directory with specific permissions.:
Explanation: This command creates a new directory named 'private_directory' with permissions set to 700 (rwx------), meaning only the owner has read, write, and execute permissions.
-
Create a directory hierarchy.:
Explanation: This command creates a directory hierarchy with dir1 as the parent, dir2 as a subdirectory of dir1, and dir3 as a subdirectory of dir2. If any of the directories already exist, no error is returned.
-
Create a directory and display verbose output.:
Output:
Explanation: This command creates a new directory named 'verbose_directory' and displays a detailed output of the command execution.
Turn Learning into Career Growth
Conclusion
-
The mkdir command is used to create new directories in Linux.
-
Various options are available to modify the behavior of the command, such as setting permissions or creating parent directories.
-
Always check for existing directories before creating new ones to avoid overwriting or errors.