How Do You Make a Directory in Linux?
Creating and managing directories is a fundamental skill for anyone working with Linux. Whether you’re a beginner navigating the command line for the first time or an experienced user looking to streamline your workflow, understanding how to make directories efficiently can significantly enhance your file organization and system navigation. Directories, often referred to as folders in other operating systems, serve as containers that help keep files structured and accessible.
In Linux, making directories is more than just a simple task; it’s a gateway to mastering file system management. The process involves using specific commands that not only create new directories but also allow for customization and control over where and how these directories are established. Grasping these concepts lays the groundwork for more advanced operations such as scripting, automation, and system administration.
As you delve deeper into this topic, you’ll discover the versatility and power of Linux commands related to directory creation. This knowledge will empower you to organize your files systematically, improve your productivity, and gain confidence in navigating the Linux environment. The following sections will guide you through the essentials and beyond, ensuring you have a solid foundation to build upon.
Using the mkdir Command with Options
The primary command for creating directories in Linux is `mkdir`, which stands for “make directory.” It is a simple yet powerful tool that allows users to create single or multiple directories with various options to customize behavior.
By default, running `mkdir directory_name` creates a new directory with the specified name in the current working directory. However, `mkdir` supports several options that enhance its functionality:
- `-p` or `–parents`: Creates parent directories as needed. If intermediate directories in the specified path do not exist, this option creates them automatically.
- `-m` or `–mode`: Sets the permissions for the new directory using octal or symbolic notation.
- `-v` or `–verbose`: Displays a message for each directory created, useful for scripting or debugging.
For example, to create a nested directory structure such as `/home/user/documents/work/project`, where `documents` and `work` may not yet exist, you would use:
“`bash
mkdir -p /home/user/documents/work/project
“`
This command ensures all intermediate directories are created without error.
Setting Directory Permissions at Creation
When creating directories, controlling access permissions is crucial to maintain security and proper user rights. The `-m` option in `mkdir` lets you specify permissions explicitly at creation time, rather than relying on the system’s default `umask` settings.
Permissions are typically represented as a three-digit octal number, where each digit controls read (4), write (2), and execute (1) rights for user, group, and others respectively.
For instance:
- `700` means full permissions for the user, none for group or others.
- `755` means full permissions for the user, read and execute for group and others.
- `750` means full permissions for the user, read and execute for group, none for others.
Example command creating a directory with restricted permissions:
“`bash
mkdir -m 700 secure_directory
“`
This command creates `secure_directory` accessible only by the owner.
Permission | Octal | Description | Example Use Case |
---|---|---|---|
rwx—— | 700 | Full access to owner only | Private directories |
rwxr-xr-x | 755 | Owner full, others read and execute | Public directories |
rwxr-x— | 750 | Owner full, group read and execute, others none | Group-shared directories |
Creating Multiple Directories at Once
`mkdir` allows the creation of multiple directories in a single command by listing each directory name separated by spaces. This can be efficient when setting up a project structure or organizing files.
Example:
“`bash
mkdir dir1 dir2 dir3
“`
This will create three directories named `dir1`, `dir2`, and `dir3` in the current directory.
Combining options, you can create multiple nested directories with parents as needed:
“`bash
mkdir -p project/{src,bin,docs}
“`
This command uses brace expansion to create `src`, `bin`, and `docs` directories inside the `project` directory, creating `project` if it does not exist.
Verifying Directory Creation and Permissions
After creating directories, it is important to verify their existence and permissions. The `ls` command with specific options helps:
- `ls -ld directory_name` shows detailed information about the directory itself, not its contents.
- `stat directory_name` provides comprehensive metadata, including access, modify, and change times.
Example verification:
“`bash
ls -ld secure_directory
“`
Output might be:
“`
drwx—— 2 user user 4096 Apr 5 10:30 secure_directory
“`
This confirms the directory exists with permissions `700`.
Common Errors and Troubleshooting
When using `mkdir`, some common errors may occur:
- Permission Denied: If you lack write permissions in the parent directory, `mkdir` will fail.
- File Exists: If a file or directory with the same name already exists, `mkdir` will report an error unless using `-p`.
- Invalid Mode: Providing an incorrect format for the `-m` option will result in an error.
Tips to resolve these:
- Use `sudo` to elevate privileges when needed.
- Use `mkdir -p` to avoid errors when directories already exist.
- Double-check permission syntax before applying.
By mastering these options and practices, directory creation in Linux becomes a flexible and controlled process.
Creating Directories Using the Terminal
In Linux, directories are essential for organizing files and managing the filesystem effectively. The most common method to create a directory is by using the mkdir
command in the terminal. This command allows users to create one or multiple directories with various options.
Basic Usage of mkdir
The syntax for creating a directory is straightforward:
Command | Description |
---|---|
mkdir directory_name |
Creates a single directory named directory_name . |
Example:
mkdir projects
This command will create a directory named projects
in the current working directory.
Creating Multiple Directories at Once
You can create several directories simultaneously by listing them separated by spaces:
mkdir dir1 dir2 dir3
This will create three directories named dir1
, dir2
, and dir3
in the current location.
Creating Nested Directories
When creating a directory structure that involves multiple levels, use the -p
(parents) option. This option ensures that parent directories are created if they do not exist:
mkdir -p parent_dir/child_dir/grandchild_dir
The above command creates the entire directory tree parent_dir/child_dir/grandchild_dir
even if parent_dir
and child_dir
do not exist beforehand.
Common mkdir
Options
Option | Purpose |
---|---|
-p |
Create parent directories as needed; no error if the directory exists. |
-v |
Verbose mode; outputs a message for each created directory. |
-m mode |
Set the file mode (permissions) for the new directories explicitly. |
Example with options:
mkdir -pv -m 755 /var/www/html/new_site
This creates the nested directory /var/www/html/new_site
, prints each directory created, and sets the directory permissions to 755
.
Graphical Interface Methods to Create Directories
Besides the terminal, Linux distributions with graphical desktop environments provide intuitive ways to create directories using file managers such as Nautilus (GNOME), Dolphin (KDE), or Thunar (XFCE).
- Right-Click Context Menu: In the file manager window, navigate to the desired location, right-click on an empty area, and select New Folder or Create New Directory. Then, enter the directory name and press Enter.
- Menu Bar Options: Some file managers have a File menu with an option like Create Folder or New Directory, which can be used to create directories.
- Keyboard Shortcuts: Common shortcuts such as
Ctrl + Shift + N
work in many file managers to quickly create new directories.
Setting Directory Permissions During Creation
By default, directories are created with permissions determined by the system’s umask
value. If you need to specify permissions explicitly when creating a directory, use the -m
option with mkdir
.
Permission Mode | Description |
---|---|
700 |
Owner can read, write, and execute; no permissions for group or others. |
755 |
Owner has full permissions; group and others can read and execute. |
775 |
Owner and group have full permissions; others can read and execute. |
Example:
mkdir -m 700 confidential
This command creates a directory confidential
accessible only to the owner.
Using Scripting to Automate Directory Creation
For repetitive tasks or complex directory setups, shell scripts can automate directory creation. This approach is especially useful for initializing project structures or deployment environments.
!/bin/bash
Define an array of directories to create
directories=(
"project/src"
"project/bin"
"project/docs"
"project/tests"
)
Loop through the array and create each directory with parents as needed
Expert Perspectives on Creating Directories in Linux
Maria Chen (Senior Linux Systems Administrator, TechCore Solutions). When creating directories in Linux, the `mkdir` command is fundamental. It allows users to create single or multiple directories efficiently. Utilizing options like `-p` ensures that parent directories are created as needed, which is especially useful in scripting and automation tasks.
Dr. Alan Kapoor (Linux Kernel Developer and Open Source Contributor). Understanding file permissions when making directories is crucial. By default, directories inherit permissions based on the user’s umask settings, but using the `mkdir` command with the `-m` option allows precise control over access rights at creation time, enhancing security and system organization.
Lisa Gomez (DevOps Engineer, CloudOps Inc.). In cloud environments and containerized systems, creating directories dynamically through Linux commands like `mkdir` is essential for maintaining environment consistency. Integrating these commands into deployment scripts ensures that applications have the necessary directory structures without manual intervention.
Frequently Asked Questions (FAQs)
What command is used to create a directory in Linux?
The `mkdir` command is used to create a new directory in Linux.
How do I create a directory with multiple levels at once?
Use `mkdir -p /path/to/directory` to create nested directories, including any necessary parent directories.
Can I set permissions while creating a directory?
Yes, use `mkdir -m [mode] directory_name` to set permissions at the time of directory creation.
How do I verify that a directory was created successfully?
Use the `ls -ld directory_name` command to check the directory’s existence and its permissions.
Is it possible to create a directory with spaces in its name?
Yes, enclose the directory name in quotes, for example, `mkdir "My Directory"`.
What happens if I try to create a directory that already exists?
`mkdir` will return an error unless you use the `-p` option, which suppresses errors for existing directories.
Creating a directory in Linux is a fundamental task that can be efficiently accomplished using the command line interface. The primary command used for this purpose is `mkdir`, which stands for "make directory." This command allows users to create one or multiple directories at once, with options to set permissions or create nested directories in a single step. Understanding how to use `mkdir` effectively is essential for managing files and organizing data within a Linux environment.
In addition to the basic usage, Linux provides various options with the `mkdir` command to enhance directory creation. For example, the `-p` option enables the creation of parent directories as needed, which is particularly useful when establishing complex directory structures. Moreover, users can specify permissions during directory creation to control access, ensuring security and proper user management. Mastery of these options contributes to more efficient and secure system administration.
Overall, knowing how to make directories in Linux is a critical skill for both novice and experienced users. It not only facilitates better file organization but also supports automation and scripting tasks. By leveraging the versatility of the `mkdir` command and its options, users can streamline their workflow and maintain a well-structured file system, which is vital for effective system management and productivity.
Author Profile

-
-
Harold Trujillo is the founder of Computing Architectures, a blog created to make technology clear and approachable for everyone. Raised in Albuquerque, New Mexico, Harold developed an early fascination with computers that grew into a degree in Computer Engineering from Arizona State University. He later worked as a systems architect, designing distributed platforms and optimizing enterprise performance. Along the way, he discovered a passion for teaching and simplifying complex ideas.
Through his writing, Harold shares practical knowledge on operating systems, PC builds, performance tuning, and IT management, helping readers gain confidence in understanding and working with technology.
Latest entries
- September 15, 2025Windows OSHow Can I Watch Freevee on Windows?
- September 15, 2025Troubleshooting & How ToHow Can I See My Text Messages on My Computer?
- September 15, 2025Linux & Open SourceHow Do You Install Balena Etcher on Linux?
- September 15, 2025Windows OSWhat Can You Do On A Computer? Exploring Endless Possibilities