Creating a new folder in Linux might sound tricky at first, but trust us, even beginners can get the hang of it. The Linux operating system offers a powerful command line where you can perform a vast array of operations. To create a new directory, you simply need to use the mkdir command. This command stands for “make directory” and it’s incredibly straightforward to use.

Imagine you want to organize your files by creating a new directory named “project.” All you need to do is open the terminal and type mkdir project. Presto! You’ve got a new home for your files. Using the command line like this doesn’t just make you look cool – it’s efficient and essential for mastering Linux.
Remember when we started our Linux journey? The command line felt like a foreign language. We were so used to the graphic interfaces of Windows and macOS. Over time, however, we realized the command line isn’t just a relic of the past. It’s a powerful tool that can significantly boost our productivity. So why not dive in and see what else you can do with commands like mkdir?
Contents
Navigating directories in Linux involves understanding paths and using basic commands to move around the filesystem. We’ll talk about paths and some essential commands like ls, cd, and pwd.
Understanding Paths
Paths in Linux can be absolute or relative. An absolute path starts from the root directory / and specifies a complete path to a file or directory starting from /.
For instance, /home/user/documents points directly to the “documents” directory in “user’s” home. We always know they start from the root.
A relative path depends on the current working directory. Unlike absolute paths, they don’t start with /. If we’re in /home/user and want to go to “documents,” we simply write documents instead of /home/user/documents.
The current working directory is the directory we are in at any given time. We can find it with the pwd command.
Basic Commands
The ls command lists the contents of a directory. It has various options to display files in detail. For example, ls -l shows a detailed list with permissions, ownership, and modification dates.
To change directories, we use the cd command. If we use cd /etc, we move to the /etc directory. We can go back to our home directory with cd ~.
To check where we currently are, we use the pwd command. It displays the full path to the current directory. For example, running pwd might return /home/user, indicating we’re in the user’s home directory.
Exploring the Linux terminal and mastering these commands helps us navigate the filesystem more efficiently.
Creating Directories with Mkdir
Creating directories in Linux is straightforward with the mkdir command, offering both basic usage and advanced options to handle various permission and parent directory requirements.
The Basics of Mkdir
When we want to create a new directory in Linux, the mkdir command is our go-to tool. By simply typing mkdir followed by the directory name, we can generate a new folder in the current working directory.
For example:
mkdir new_folder
This command will create a directory named new_folder. We can verify that the directory has been created using the ls command:
ls -l
If we need to create multiple directories at once, we can do so by specifying multiple directory names:
mkdir dir1 dir2 dir3
This above command creates three directories named dir1, dir2, and dir3.
Advanced Mkdir Options
The mkdir command also comes with several options to create directories with specific parameters. One useful option is -p, which allows us to create parent directories along with the new directory:
mkdir -p parent_folder/child_folder
This command will create both parent_folder and child_folder if they do not already exist.
Another crucial option is -m which sets permissions for the new directory. For example:
mkdir -m 755 new_secure_folder
This will create new_secure_folder with read, write, and execute permissions for the owner, and read and execute permissions for the group and others.
These options allow us to efficiently manage the creation of directories in various scenarios, ensuring our file system remains organized and secure.
Linux File Permissions
Permissions in Linux determine who can access, read, write, or execute files and directories. Understanding and controlling these permissions is crucial for maintaining system security and file integrity.
Understanding File Permissions
File permissions in Linux are categorized into three types: read (r), write (w), and execute (x). These permissions can be assigned to three classes: the owner, the group, and others.
Permissions are typically displayed in a string format like rwxr-xr--. Here, the first three characters (rwx) represent the owner’s permissions, the next three (r-x) represent the group’s permissions, and the last three (r--) represent the permissions for others.
| Symbol | Permission | Description |
| r | Read | View file contents |
| w | Write | Modify file contents |
| x | Execute | Run file as a program |
It’s important to understand these symbols and what they represent to avoid a “permission denied error.” If a file or directory doesn’t have the correct permissions, users might be restricted in ways that impede functionality.
Modifying Access Rights
We can modify file permissions using the chmod command. To grant specific permissions to a file, we use numerical or symbolic modes. For instance, to set read, write, and execute permissions for the owner and read-only for others, we use:
chmod 744 filename
Here, 744 breaks down as:
- 7 for the owner (
rwx) - 4 for the group (
r--) - 4 for others (
r--)
For directories, add the -R option to change permissions recursively:
chmod -R 755 directoryname
SELinux provides additional security contexts beyond standard permissions. We can modify these with the chcon command, allowing more granular control over how processes access files.
These commands ensure we can control access levels effectively. Whether we’re updating permissions on a new folder or troubleshooting access issues, these tools are indispensable. Addressing permission settings accurately helps prevent unauthorized access and maintains system integrity.
Additional Directory Management Commands
When managing directories in Linux, it’s crucial to know how to both create and remove them effectively. Removing directories, particularly nested ones, can be a bit tricky without the proper commands.
Removing Directories
Removing directories is an essential part of directory management. In Linux, we use the rmdir command to remove empty directories.
If a directory contains files or subdirectories, rmdir won’t work. Instead, we use the rm command with the -r option, which stands for recursive. This will remove the directory along with all its contents.
Example:
To remove a directory named old_dir and all its content, use:
rm -r old_dir
Using the -v (verbose) option gives us detailed information about what is being removed:
rm -rv old_dir
Be cautious! Using these commands, especially on important directories, could result in data loss. Always double-check the directory name and its contents before proceeding with removal.