📅  最后修改于: 2023-12-03 14:39:27.765000             🧑  作者: Mango
If you are working with Bash and need to create multiple directories at once, the mkdir
command can help you make your life easier. In this article, we will show you how to use the mkdir
command to create multiple directories at once.
The syntax for creating directories with the mkdir command is as follows:
mkdir [OPTION]... DIRECTORY...
Here, [OPTION]
represents any options that you want to pass to the command, and DIRECTORY
represents the name of the directory that you want to create. You can specify multiple directories separated by spaces.
To create multiple directories at once, you simply need to specify the names of each directory you want to create as follows:
mkdir directory1 directory2 directory3
You can also use wildcards to create directories with a similar naming convention. For example, to create five directories with names dir1
, dir2
, dir3
, dir4
, and dir5
, you can enter:
mkdir dir{1..5}
The {1..5}
part of the command is a Bash shorthand for generating a sequence of numbers from 1 to 5. The curly braces {}
are used to group the numbers together and specify that they should be treated as a sequence.
There are several options you can use with the mkdir command to customize the way directories are created:
-p
: Create parent directories if they do not exist already.-m
: Set the file mode (permissions) for the created directory. For example, you can enter -m 0777
to make the directory readable and writable by anyone.-v
: Display a message for each directory created.Here's an example of using the -p
option:
mkdir -p parentdir/childdir/grandchilddir
This command will create a directory structure where parentdir
contains childdir
, which in turn contains grandchilddir
.
Using the mkdir
command is a quick and easy way to create multiple directories at once in Bash. By using options like -p
, -m
, and -v
, you can customize the way directories are created to better suit your needs.