mkdir Linux Command Guide
The Linux mkdir command is used to create directories in the file system. It allows users to specify the names of the directories they want to create and can also create multiple directories at once. By using the mkdir command, users can organize their files and data efficiently. Overall, the mkdir command is a simple yet powerful tool for managing directories in a Linux environment.
mkdir Syntax:
Options:
Option | Description |
---|---|
-m | Set file mode (permissions) of the created directory |
-p | Create parent directories as needed |
-v | Print a message for each created directory |
Parameters:
Parameter | Description |
---|---|
directory_name | Name of the directory to be created |
mkdir Command Samples:
Create a New Directory
Creates a new directory named “new_directory” in the current location.
Create Nested Directories
Creates a parent directory named “parent_directory” and a nested child directory named “child_directory” within it.
Verbose Mode
Creates multiple directories (“directory1”, “directory2”, “directory3”) and displays a message for each directory created.
Specify Permissions
Creates a directory named “secure_directory” with permissions set to 755 (read, write, execute for owner; read and execute for group and others).
Create Directory with Spaces
Creates a directory with a name containing spaces by encapsulating the directory name within double quotes.
Create Directory with Parent
Creates directories starting with “parent_directory” followed by “child_directory”, and finally “grandchild_directory” as a nested directory.
Create Directories with Specific Group
Creates directories for projects “project1” and “project2” with the group ownership set to “developers”.
mkdir FAQ:
How do I use mkdir in Linux?
To use the mkdir command in Linux, execute the following command:
What is the purpose of the -p option in mkdir?
The -p option in mkdir is used to create parent directories along with the specified directory. This is useful when you want to create a directory and its parent directories if they do not already exist.
How can I set permissions for a directory while creating it with mkdir?
You can set permissions for a directory while creating it by using the chmod command in combination with the mkdir command. Here is an example:
How can I create multiple directories at once with mkdir?
To create multiple directories at once with mkdir, you can specify the directory names separated by spaces in a single command. Here is an example:
How do I prevent mkdir from displaying error messages if the directory already exists?
You can prevent mkdir from displaying error messages if the directory already exists by using the -p option. This option ensures that no error message is shown if the directory is already present.
Can I use mkdir to create directories with spaces in their names?
Yes, you can create directories with spaces in their names by enclosing the directory name in quotes. Here is an example:
Applications of the mkdir command
- Create a new directory
- Create multiple directories at once
- Create directories with specific permissions
- Create parent directories as needed with the -p option
- Create directories with symbolic links or absolute paths
- Create nested directories efficiently