Command
mkdirExplanation
The `mkdir` (make directory) command creates one or more directories. The `-p` option ensures that no error occurs if the directory already exists and allows creation of full directory paths. It’s commonly used for preparing folder structures in scripts and deployments.
Common Use Cases
- •Prepare project folder structures
- •Create nested directories automatically
- •Set up data storage directories for applications
Best Practices
- ✓Use `-p` to avoid errors when directories exist
- ✓Combine with `chmod` to set permissions immediately after creation
Common Mistakes to Avoid
- ⚠Forgetting to use `-p` when creating nested directories
- ⚠Attempting to create directories without write permissions
Troubleshooting
Problem: Permission denied creating directory
Solution: Use `sudo mkdir` for system paths or verify directory ownership.
Problem: Cannot create nested directories
Solution: Include `-p` to create parent directories automatically.
Examples
Create a single directory
mkdir newdirCreate nested directories
mkdir -p path/to/newdir