Create directories
The mkdir command is used to create one or more directories. If no path is provided, the directory is created in the current working directory. If an existing path is specified, the directory is created within that path. When creating a directory, ensure that its name does not conflict with existing files or directories in the same location.
Organizing files into subdirectories (e.g., by type or purpose) is a best practice for effective file management.
mkdir [OPTION]... DIRECTORY...
-Z: Set the SELinux security context.
-m, --mode <MODE>: Set the file mode (permissions) for the new directory.
-p, --parents: Create parent directories as needed. No error if they already exist.
--version: Display version information.
Directory: A space-separated list of directories to be created.
Create a subdirectory named test in /usr/meng with permissions set to 700 (read, write, and execute for the owner only):
mkdir -m 700 /usr/meng/test
Create a directory bin and its subdirectory os_1 in the current directory, with permissions set to 750 (owner: rwx, group: r-x, others: none):
mkdir -p -m 750 bin/os_1
The -m option configures directory permissions using a three-digit numeric code:
Each digit is a sum of:
For example, 755 corresponds to:
7 (Owner) = 4 + 2 + 1 = rwx5 (Group) = 4 + 1 = r-x5 (Others) = 4 + 1 = r-x