+4 votes
in Operating Systems by (60.1k points)

I want to create multiple directories with multiple subdirectories inside them. Which Linux command will do the job?

E.g.

Directories:

Subdir_1, Subdir_2, .... Subdir_5

And inside these directories:

Subdir11, Subdir12

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

You can use the "mkdir" command with the "-p" option to create directories and subdirectories inside them.

Here is an example:

mkdir -p subdir_{1..5}/{lowdir1,lowdir2}

This command will create subdir_1....subdir_5
Inside these directories, subdirectories lowdir1 and lowdir2 will be created.

The directory structure will look the following:

subdir_1/lowdir1
subdir_1/lowdir2
subdir_2/lowdir1
subdir_2/lowdir2
.
.
.
subdir_5/lowdir1
subdir_5/lowdir2


...