How to Create a New Folder in Linux: Step-by-Step Guide for Beginners

Thinking about creating a new folder in Linux might initially seem a bit daunting, but it’s a breeze once we get the hang of it. To create a directory in Linux, we can use the mkdir command followed by the name of the directory we want to create. This simple command is a cornerstone of Linux file management, and mastering it opens up a range of organizational possibilities.

How to Create a New Folder in Linux: Step-by-Step Guide for Beginners

Let’s imagine we’re working on a project, and we need to organize our files better. We would open the terminal, type mkdir project_files, and boom – a new directory named project_files is created. This new directory can now hold all the relevant documents, scripts, and assets. In Linux, directories play a crucial role in keeping our work neat and accessible.

Creating directories isn’t just about organization; it’s a fundamental skill that underscores more advanced operations. By using mkdir regularly, we build a solid foundation for efficient file management. Think of directories as digital folders that allow us to compartmentalize tasks and resources. This habit not only saves time but also enhances our productivity in the long run.

Creating Directories with Mkdir Command

Let’s dive into how to create directories in Linux using the mkdir command. We’ll cover the basics, creating multiple directories, handling permissions, and dealing with errors.

Understanding the Basics of Mkdir

The mkdir command in Linux allows us to create new directories with ease. By typing mkdir directory_name into the terminal, we can make a directory named “directory_name” in the current path.

For example:

mkdir my_folder

Verify the creation with ls:

ls -l

The new directory should appear in the list. It’s a straightforward command but extremely powerful for organizing our files.

Creating Multiple Directories and Nested Directories

Creating multiple directories at once can save us a lot of time. We simply list the directory names in the mkdir command:

mkdir dir1 dir2 dir3

This command creates dir1, dir2, and dir3 simultaneously.

For nested directories (folders within folders), we use the -p flag:

mkdir -p project/{src,bin,docs}

This creates a project directory with src, bin, and docs subdirectories. The -p ensures all parent directories are created as needed.

Handling Permissions with Mkdir

File permissions are crucial for controlling access. By default, new directories have specific permissions. To modify these, we use the chmod command.

Here’s how to set permissions:

chmod 755 new_directory

This command gives the owner full permissions while others receive read and execute permissions. If we encounter “permission denied” errors, it means our current user lacks the required permissions.

We use the sudo command to gain the necessary privileges:

sudo mkdir protected_directory

This creates directories with elevated permissions, ensuring smooth operation.

Error Handling and Feedback

Errors are part of the learning curve with Linux commands. Common errors with mkdir include “File exists” or “Permission denied.”

When encountering a “File exists” error:

mkdir existing_directory

Since the directory already exists, no action is taken.

Permission errors often arise without sufficient rights:

mkdir /protected/newdir

Attempting without sudo can lead to issues. Always check the path and permissions.

Linux provides helpful error messages to guide us through fixes. By carefully reading and understanding these feedbacks, we can resolve errors efficiently and continue creating directories without hitches.


By mastering the mkdir command, we empower ourselves to organize and manage our Linux file systems effectively. From basic usage to handling permissions and troubleshooting, this knowledge is vital for any Linux user.

Manipulating Directories

In Linux, working with directories involves a few key operations. We’ll discuss how to delete directories, list directory contents, and change the current working directory.

Using Rm Command to Delete Directories

When you need to remove directories, the rm or rmdir commands are essential. With rm -r, you can recursively delete a directory and all its contents. This command is powerful, and one small mistake can lead to data loss. Always remember to double-check the directory names before executing the command.

For example, to delete a directory named old_dir and all its contents:

rm -r old_dir

For empty directories, use the rmdir command:

rmdir empty_dir

Using these commands safely avoids accidental file deletion and ensures the integrity of your directory structure.

Listing Directories with Ls Command

The ls command is our go-to tool for listing directory contents. It’s versatile and offers several options for detailed views. Use ls -l for a long listing format, which provides information such as permissions, number of links, owner, group, size, and modification date.

To list all files, including hidden ones (those starting with a dot):

ls -la

Hidden files are essential in many cases, especially when dealing with configuration files. Customizing the ls command with various options helps us manage our files and directories more effectively.

Changing Directory Context with Cd Command

Navigating directories is straightforward with the cd command. This command changes the current working directory, allowing us to move through the file system efficiently. To move to a directory named new_dir:

cd new_dir

We can use relative paths to navigate through the directory structure:

cd ../parent_dir

This command takes us up one level in the directory tree. Being comfortable with cd enhances our ability to work within the Linux environment, making it crucial for effective directory manipulation.

Advanced Mkdir Command Techniques

Exploring some of the advanced techniques with the mkdir command can make our Linux experience more efficient. We’ll cover how to create nested directories and set specific permissions when creating directories.

Using -P Option for Parent Directories

The -P option is a powerhouse for creating hierarchical structures. Imagine you need to create multiple nested directories in one shot:

mkdir -p parent/child/grandchild

This command ensures that if any of the parent directories don’t exist, the system will create them. If parent or child directories are missing, no worries—mkdir -p takes care of it. Want to check if it worked? Just use the ls command to see the newly created directory tree. This feature is extremely useful for initializing complex project structures quickly and error-free.

Setting Directory Mode with -M Option

We can also set specific permissions for our new directory using the -m option. This allows us to define a default file mode. By customizing directory permissions at creation, we improve security and manage access more effectively:

mkdir -m 755 new_directory

Here, 755 sets read, write, and execute permissions for the owner, and read and execute permissions for others. It’s essential to choose the correct mode when dealing with sensitive data or collaborative environments. Checking the permissions can be done using the ls -l command, showing us a detailed list including the permissions.

Leave a Comment