Recent Articles

Thursday, February 17, 2022

Create Multiple Directories Via Linux Command | Using Every Possible mkdir Commands?

Well, you can easily create multiple directories in Linux by using mkdir command repetitively. However, you can use other commands to perform this task faster.


Let's create multiple directories by using the mkdir command at first. Suppose you want to create a new directory and, a couple of subdirectories inside that directory. We'll use the mkdir command to create a directory first, after creating the directory, we'll jump inside the directory by using the cd command, and again, we'll use the mkdir command several times to create subdirectories.


Here in the above image, you can seed that firstly I've created a directory with rsh name, used the cd command to jump inside the newly created directory, and created several more subdirectories my using the mkdir command several times.

However, if you don't want to repeat the same command several times and instead of this, want to do this task more efficiently, then you can use mkdir directory1 directory2 directory3 command. 



The above command is used to create several subdirectories inside a directory but, If you want to create several subdirectories while creating a directory then you can use the mkdir -p directoryname/{subdirectory1,subdirectory2,subdirectory3} command.


As you can see the above command has created a new directory and several subdirectories inside it at the same time. You can still expand the command by creating subdirectories inside the directory while creating a directory. It seems slightly confusing but it isn't as confusing at the practical level as it looks in writing.


See the above image, I've created a directory name rsh, created a subdirectory name, FirstDirectory, and inside the FirstDirectory folder, I created 3 more directories named sub1, sub2, sub3, and all these with a single command.

Four directories are created inside the rsh directory and then three subdirectories, inside the FirstDirectory subdirectory.


These are some of the best use of the mkdir command in a directory creation. Moreover, If you desire to learn more about the Linux commands then you can visit RedserverHost.Com's official website which is blog.redserverhost.com because they've written some great articles about Linux commands & their uses.






No comments:

Post a Comment