Files & folders

Linux mkdir command

Create a directory. The -p flag also creates missing parent directories.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

mkdir [OPTION]... DIRECTORY...

Examples

Create a directory tree, including missing parents.

mkdir -p ~/projects/demo/src

Create a directory with mode 750.

mkdir -m 750 private-data

Parameters, options and clauses

Option / clauseDescription
-p, --parentsCreate missing parent directories; do not fail if they exist.
-m, --mode=MODESet permissions using a symbolic or numeric mode.
-v, --verbosePrint a message for each created directory.
-ZSet the SELinux security context on created directories.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory