Bash mkdir and subfolders

BashMkdirGit Bash

Bash Problem Overview


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?

Bash Solutions


Solution 1 - Bash

You can:

mkdir -p folder/subfolder

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

Solution 2 - Bash

To create multiple sub-folders

mkdir -p parentfolder/{subfolder1,subfolder2,subfolder3}

Solution 3 - Bash

FWIW,

Poor mans security folder (to protect a public shared folder from little prying eyes ;) )

mkdir -p {0..9}/{0..9}/{0..9}/{0..9}

Now you can put your files in a pin numbered folder. Not exactly waterproof, but it's a barrier for the youngest.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUffoView Question on Stackoverflow
Solution 1 - BashFatalErrorView Answer on Stackoverflow
Solution 2 - Bashdanleyb2View Answer on Stackoverflow
Solution 3 - BashMutraxView Answer on Stackoverflow