mkdir
Quick Reference
Command Name:
mkdir
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Directory creation
Create new directories in the filesystem
- 2
File organization
Organize files and directories hierarchically
- 3
Project setup
Create project directories for new projects
- 4
Temporary directories
Create temporary directories for temporary files
Syntax
mkdir [OPTION]... DIRECTORY...
Options
Option | Description |
---|---|
-m, --mode=MODE | Set file mode (permissions) as in chmod (default: 0777) |
-p, --parents | Create parent directories as needed, no error if existing |
-v, --verbose | Print a message for each created directory |
-Z | Set SELinux security context of each created directory to default type |
--context[=CTX] | Like -Z, or if CTX is specified, set the SELinux or SMACK security context to CTX |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the mkdir
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
mkdir documents
Creates a new directory named documents in the current working directory. This is the most basic usage of mkdir.
mkdir dir1 dir2 dir3
Creates multiple directories at once. This example creates three directories named dir1, dir2, and dir3 in the current location.
mkdir -p projects/website/html
Creates nested directories in a single command. The -p option creates parent directories if they don't exist. This command creates projects, then website inside it, then html inside that.
mkdir -m 755 secure_folder
Creates a directory with specific permissions. This command creates secure_folder with permissions set to 755 (rwxr-xr-x), which gives read, write, and execute permissions to the owner, and read and execute permissions to group and others.
Advanced Examples:
mkdir -p -v project/{src,docs,tests}/{main,lib}
Creates a complex directory structure using brace expansion. This creates a project directory with subdirectories for source code, documentation, and tests, each having main and lib subdirectories. The -v option provides verbose output showing each directory as it's created.
mkdir -p "My Photos/Vacation 2023"
Creates a directory with spaces in its name. When directory names contain spaces, they should be enclosed in quotes to be properly interpreted.