Linux command
mkdir 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Create a directory
mkdir [directory]
Create multiple directories
mkdir [dir1] [dir2] [dir3]
Create parent directories
mkdir -p [path/to/nested/directory]
Create a directory with specific permissions
mkdir -m [755] [directory]
Create directories and show a message
mkdir -v [dir1] [dir2]
说明
mkdir creates directories with the specified names. By default, it creates the directory in the current working directory or at the specified path. The -p option is particularly useful for creating nested directory structures in a single command, as it creates all necessary parent directories and does not report an error if the target directory already exists. This makes it ideal for scripts where the directory may or may not exist. Permissions for the new directory are affected by the current umask unless explicitly set with -m. The default permission is typically 777 minus the umask value.
参数
- -p, --parents
- Create parent directories as needed; no error if existing
- -m _mode_, --mode=_mode_
- Set file mode (permissions) for the new directory
- -v, --verbose
- Print a message for each created directory
- -Z, --context
- Set SELinux security context of each created directory
- --help
- Display help information and exit
- --version
- Output version information and exit
FAQ
What is the mkdir command used for?
mkdir creates directories with the specified names. By default, it creates the directory in the current working directory or at the specified path. The -p option is particularly useful for creating nested directory structures in a single command, as it creates all necessary parent directories and does not report an error if the target directory already exists. This makes it ideal for scripts where the directory may or may not exist. Permissions for the new directory are affected by the current umask unless explicitly set with -m. The default permission is typically 777 minus the umask value.
How do I run a basic mkdir example?
Run `mkdir [directory]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p, --parents do in mkdir?
Create parent directories as needed; no error if existing