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?

1

You can:

mkdir -p folder/subfolder

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

1

To create multiple sub-folders

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

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.

3
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest