mkdir Command in Linux

Learn via video courses
Topics Covered

Overview

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.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.

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.

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more