乐闻世界logo
搜索文章和话题

What is mkdir in Linux?

1个答案

1

Basic Usage

The basic command format is:

bash
mkdir [options] directory_name

Here, "directory_name" can be any name you want to create. If the directory name contains spaces, enclose it in quotes.

Examples

  1. Creating a single directory:
bash
mkdir mydirectory

This command creates a new directory named mydirectory in the current working directory. 2. Creating multiple directories:

bash
mkdir dir1 dir2 dir3

This command creates three directories: dir1, dir2, and dir3. 3. Creating multi-level directories:

bash
mkdir -p parent/child/grandchild

Using the -p option ensures that all necessary parent directories are created when creating grandchild, even if they did not exist previously.

Advanced Options

  • -p (parents): As previously mentioned, this option allows creating multi-level directory structures, ensuring that all specified parent directories are created if they do not exist.
  • -m (mode): Allows users to specify directory permissions. For example: mkdir -m 755 newdir creates a directory that is readable and executable by all users but writable only by the owner.

Use Cases

In software development, you may need to create specific directory structures to store code, test files, logs, etc. For example, when initializing a new project, you need to create many folders for different purposes, making the mkdir command very useful.

2024年8月14日 13:11 回复

你的答案