Syntax
Description
Themkdir command creates one or more directories within Nash’s virtual filesystem. By default, it creates only the final directory in a path and fails if parent directories don’t exist. With the -p flag, it creates all necessary parent directories automatically.
All directories are created within Nash’s Virtual Filesystem (VFS). To create directories on the host system, you must mount a host directory with write permissions using
--bind.Options
Create parent directories as needed. If parent directories already exist, no error is reported. This allows creating deep directory structures in a single command.
Arguments
One or more directory paths to create. Can be absolute paths (starting with
/) or relative paths from the current working directory. Multiple directories can be specified separated by spaces.Behavior
- Without
-p: Creates only the final directory, fails if parent directories don’t exist - With
-p: Creates all parent directories in the path automatically - Multiple directories: Can create several directories in one command
- Existing directories: With
-p, silently succeeds if directory already exists; without-p, may report error - Path resolution: Relative paths are resolved from current working directory
Examples
Create a single directory
Create multiple directories
Create nested directories with -p
Create directory with absolute path
Create multiple nested paths
Use in command chains
Create and populate directory
Error Handling
Missing operand
Parent directory doesn’t exist (without -p)
-p flag:
Directory already exists
With-p flag, this silently succeeds:
Invalid path
VFS Integration
Creating directories in mounted volumes
When working with mounted host directories (read-write),mkdir creates real directories on the host:
Read-only mounts
Attempting to create directories in read-only mounted paths will fail:Common Patterns
Project scaffolding
Temporary workspace
Date-based directories
Conditional directory creation
Combining with Other Commands
With cd to navigate into new directory
With find to verify creation
With tree to visualize structure
With touch to create files
Exit Codes
- 0 - Success: all directories created successfully
- 1 - Error: missing operand or directory creation failed
Related Commands
cd- Change to the newly created directoryrmdir- Remove empty directories (userm -rfor non-empty)ls- List directory contentstree- Display directory structurepwd- Show current directoryfind- Search for directories with-type d
Implementation Details
Themkdir command is implemented in /home/daytona/workspace/source/src/builtins/mkdir.rs:9-35. Key implementation notes:
- Parses arguments to separate
-pflag from directory paths - Without
-p: callsvfs.mkdir()which creates only the final directory - With
-p: callsvfs.mkdir_p()which creates all parent directories - All paths are resolved relative to current working directory using
VfsPath::join() - Returns error if no directory paths are provided
- Processes all directories even if some fail (doesn’t stop at first error)
Comparison to Traditional Unix mkdir
Nash’smkdir implements the most common functionality:
| Feature | Nash mkdir | Unix mkdir |
|---|---|---|
-p flag | ✓ Supported | ✓ Supported |
-m mode | ✗ Not supported | ✓ Set permissions |
-v verbose | ✗ Not supported | ✓ Print created directories |
| Multiple directories | ✓ Supported | ✓ Supported |
| Permissions | N/A (VFS has no permissions) | Configurable |
Nash’s VFS doesn’t implement Unix file permissions, so the
-m flag for setting directory modes is not needed.