SoFunction
Updated on 2025-03-09

Detailed explanation of linux mkdir command

mkdir commandUsed to create a directory. This command creates a directory named by dirname. If no path name is added before the directory name, the directory specified by dirname is created in the current directory; if an existing path is given, a specified directory will be created in that directory. When creating a directory, you should ensure that the newly created directory does not have a duplicate name with the file in the directory where it is located.

Note: When creating files, do not store all files in the home directory. You can create subdirectories to organize files more effectively. It is best to use consistent naming methods to distinguish files and directories. For example, a directory name can start with capital letters, so that the directory name appears in the directory list.

A subdirectory should contain files of similar types or similar purposes. For example, a subdirectory should be created that contains all database files, another subdirectory should contain spreadsheet files, and a subdirectory should contain word processing documents, etc. Directories are also files. They follow the same naming rules as ordinary files, and use full paths to uniquely specify a directory.

grammar

mkdir (Options)(parameter)

Options

-Z:Setting up security context,When usingSELinuxValid when;-m<Target attributes>or--mode<Target attributes>Set permissions for directories while creating them;-por--parents If the upper directory to be created has not been created yet,Then the upper directory will be created together;--version Display version information。

parameter

Directory: Specifies the list of directories to be created, separated by spaces between multiple directories.

Example

In the directory/usr/mengCreate a subdirectory test under the file, and only the file owner has read, write and execute permissions, and others do not have access to it.

mkdir -m 700 /usr/meng/test

Create the os_1 directory under bin and bin in the current directory, and set the permissions to be readable, written, and executed by the file. Users in the same group can read and execute, and other users do not have permission to access it.

mkdir -p-m 750 bin/os_1

Summarize

The above is a detailed explanation of the linux mkdir command introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!