mkdir – Make Directories
The mkdir command is used to create one or more directories in a specified location.
Syntax
mkdir [OPTION]... DIRECTORY...
- You can specify one or multiple directory names.
- If no path is given, directories are created in the current working directory.
Options
| Option | Description |
|---|---|
-p |
Create parent directories as needed (no error if existing) |
-v |
Verbose: print a message for each created directory |
-m MODE |
Set file mode (permissions) for the new directory, e.g., -m 755 |
--help |
Display help message and exit |
Practical Examples
1. Create a single directory
mkdir myfolder
Creates a directory named myfolder in the current directory.
2. Create multiple directories at once
mkdir folder1 folder2 folder3
Creates three directories named folder1, folder2, and folder3.
3. Create a directory and any necessary parent directories
mkdir -p projects/2025/october
Creates the whole path projects/2025/october, creating projects and 2025 if they do not exist.
4. Create directories with specific permissions
mkdir -m 700 secure_folder
Creates secure_folder with permissions set to rwx------ (only accessible by owner).
5. Verbose output when creating directories
mkdir -v newfolder
Output:
mkdir: created directory 'newfolder'
6. Attempt to create a directory that already exists (without -p)
mkdir existing_folder
If existing_folder exists, this will result in an error like:
mkdir: cannot create directory ‘existing_folder’: File exists
Tips
- Use
mkdir -pto avoid errors when creating nested directories. - Combine with variables, for example:
mkdir -p ~/projects/{2023,2024,2025}
Creates three directories 2023, 2024, and 2025 inside ~/projects.
- Directory permissions are affected by the current
umaskunless overridden by-m.
See Also
rmdir– remove empty directoriesrm -r– remove directories recursivelychmod– change permissions of directories and filesls -ld– list directory permissions and details
Summary
mkdir is a simple yet powerful tool to create directories, especially when combined with the -p option to build entire directory trees in one go.