mkdir
Overview
The mkdir
(make directory) command creates new directories. It can create multiple directories at once and create parent directories as needed.
Syntax
mkdir [options] directory...
Common Options
Option | Description |
---|---|
-p |
Create parent directories as needed |
-m mode |
Set file mode/permissions |
-v |
Print message for each directory |
-Z |
Set SELinux security context |
--help |
Display help message |
--version |
Output version information |
-context |
Set complete SELinux context |
Key Use Cases
- Create new directories
- Create directory hierarchies
- Set directory permissions
- Create multiple directories
- Create parent directories
Examples with Explanations
Example 1: Basic Usage
mkdir new_directory
Create a single directory
Example 2: Create Parents
mkdir -p parent/child/grandchild
Create directory hierarchy
Example 3: Set Permissions
mkdir -m 755 secure_dir
Create directory with specific permissions
Understanding Output
- No output by default
- With -v:
- Created directory messages
- Error messages for:
- Permission denied
- File exists
- Invalid path
- No space
Common Usage Patterns
Create multiple directories:
mkdir dir1 dir2 dir3
Create with parents:
mkdir -p /path/to/new/dir
Create with permissions:
mkdir -m 700 private_dir
Performance Analysis
- Fast operation
- Minimal system impact
- Parent creation overhead
- Permission checking
- Directory entry updates