Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash mkdir and subfolders [duplicate]

Why I can't do something like this? mkdir folder/subfolder/ in order to achive this I have to do:

mkdir folder cd folder mkdir subfolder 

Is there a better way to do it?

like image 553
Uffo Avatar asked Feb 11 '12 17:02

Uffo


People also ask

Does mkdir create subdirectories?

Creation of an entire directory tree can be accomplished with the mkdir command, which (as its name suggests) is used to make directories. The -p option tells mkdir to create not only a subdirectory but also any of its parent directories that do not already exist.

How do I make multiple folders in one mkdir command?

You can create directories one by one with mkdir, but this can be time-consuming. To avoid that, you can run a single mkdir command to create multiple directories at once. To do so, use the curly brackets {} with mkdir and state the directory names, separated by a comma.

How do I create a directory with subdirectories in Linux?

If you want to create a directory containing several subdirectories, or a directory tree, using the command line in Linux, generally you have to use the mkdir command several times.

How do I use mkdir in bash?

The first step in creating a new directory is to navigate to the directory that you would like to be the parent directory to this new directory using cd . Then, use the command mkdir followed by the name you would like to give the new directory (e.g. mkdir directory-name ).


2 Answers

You can:

mkdir -p folder/subfolder 

The -p flag causes any parent directories to be created if necessary.

like image 172
FatalError Avatar answered Oct 22 '22 06:10

FatalError


To create multiple sub-folders

mkdir -p parentfolder/{subfolder1,subfolder2,subfolder3} 
like image 42
danleyb2 Avatar answered Oct 22 '22 06:10

danleyb2