Mastering Linux- Step-by-Step Guide to Creating New Directories
How to Create a New Directory in Linux
Creating a new directory in Linux is a fundamental task that every user should be familiar with. Whether you are a beginner or an experienced user, understanding how to create directories is crucial for organizing your files and maintaining a structured file system. In this article, we will guide you through the process of creating a new directory in Linux using various commands.
Using the `mkdir` Command
The most commonly used command to create a new directory in Linux is `mkdir`. This command stands for “make directory.” To create a new directory, simply open your terminal and type the following command:
“`
mkdir directory_name
“`
Replace `directory_name` with the desired name for your new directory. For example, if you want to create a directory named “documents,” you would use the following command:
“`
mkdir documents
“`
After executing this command, the new directory will be created in the current working directory.
Creating a Directory with Specific Permissions
When creating a new directory, you may want to set specific permissions to control access to the directory and its contents. You can do this by using the `-m` option with the `mkdir` command. This option allows you to specify the permissions for the new directory.
For example, to create a directory named “photos” with read, write, and execute permissions for the owner and read and execute permissions for others, you would use the following command:
“`
mkdir -m 755 photos
“`
In this example, the permissions are represented using octal notation. The number `755` represents the following permissions:
– The first digit (7) represents read, write, and execute permissions for the owner.
– The second digit (5) represents read and execute permissions for the group.
– The third digit (5) represents read and execute permissions for others.
Creating a Directory in a Specific Location
You can also create a new directory in a specific location by specifying the path as an argument to the `mkdir` command. To do this, use the following syntax:
“`
mkdir -p path/to/directory
“`
The `-p` option ensures that any necessary parent directories are created as well. For example, if you want to create a directory named “music” inside a directory named “downloads,” you would use the following command:
“`
mkdir -p downloads/music
“`
This command will create the “music” directory inside the “downloads” directory, even if the “downloads” directory does not exist.
Using the `cd` Command to Navigate to the New Directory
Once you have created a new directory, you may want to navigate to it using the `cd` (change directory) command. To do this, simply type the following command:
“`
cd directory_name
“`
Replace `directory_name` with the name of the directory you created. For example, to navigate to the “documents” directory, you would use the following command:
“`
cd documents
“`
By following these steps, you can easily create new directories in Linux and organize your files efficiently. Remember to explore the various options and features of the `mkdir` command to enhance your file management skills.