Linux – mkdir Command

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.



Tutorials dojo strip

Initial Example

Using mkdir to create a new directory called NewFolder:

mkdir NewFolder




MKDIR Parameters

ParameterDescription
-m, --mode=MODESet custom permissions for the new directory (similar to how chmod works)
-p, --parentsCreate parent directories as needed without errors if they already exist, leaving their permissions unchanged
-v, --verboseOutput a message for each directory that is successfully created
-ZApply 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
--helpDisplay usage information and exit
--versionShow 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




Linux Playground

Scroll to Top