Online Linux Terminal Logo
OnlineLinuxTerminal
File OperationsCLI Reference

$mkdir

Create new directories and folder hierarchies.

Syntax DefinitionPOSIX standard
mkdir [OPTIONS] DIRECTORY...
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `mkdir` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How mkdir Works

`mkdir` (Make Directory) creates one or more new directories in the file system. With the `-p` (parents) flag, it can create complete nested directory paths in a single command without throwing errors if intermediate folders already exist.

Common Flags & Command Options

Flag / OptionDescription
-p, --parentsCreate intermediate parent directories as needed without error if existing.
-m, --mode=MODESet file permission mode for new directories upon creation (e.g., -m 700).
-v, --verbosePrint a confirmation message for every created directory.

Practical Real-World Examples

Example #1Create nested directory hierarchy in one step
mkdir -p /home/user/workspace/src/components && ls -R /home/user/workspace

Creates workspace, src, and components directories automatically.

Sample Output:
/home/user/workspace: src /home/user/workspace/src: components

Frequently Asked Questions

Why should you always use mkdir -p in scripts?

`-p` prevents scripts from failing if the directory already exists and ensures all necessary parent directories are created automatically.