The mkdir
command stands for “make directory.” It is used to create new directories in the file system. By using the mkdir
command, you can organize files into different directories, making file management easier and more efficient.
Initial Example
Using mkdir
to create a new directory called NewFolder
:
mkdir NewFolder
MKDIR Parameters
Parameter | Description |
---|---|
-m, --mode=MODE | Set custom permissions for the new directory (similar to how chmod works) |
-p, --parents | Create parent directories as needed without errors if they already exist, leaving their permissions unchanged |
-v, --verbose | Output a message for each directory that is successfully created |
-Z | Apply the default SELinux security context to each newly created directory |
--context[=CTX] | Set the SELinux or SMACK security context to CTX; if CTX is omitted, use the default context |
--help | Display usage information and exit |
--version | Show version information and exit |
Examples
1. Create a New Directory
To create a single directory:
mkdir NewFolder
2. Create Multiple Directories
To create multiple directories at once, specify the names separated by spaces:
mkdir Dir1 Dir2 Dir3
3. Create Nested Directories
To create a directory structure with nested directories, use the -p
option:
mkdir -p ParentDir/ChildDir/GrandChildDir
4. Set Directory Permissions While Creating
To create a directory with specific permissions, use the -m
option followed by the permission code:
mkdir -m 755 NewFolder