How can I create several subfolders in folder in one command.

For example, I want to create:

/home/user/*create dir1*/*create dir2*/*create dir3*/

Provided, I don't have dir1. And I can't use 3 command, and can't use shell script. This creating must be in one shell command.

$ mkdir /home/user/TEST1/TEST2/TEST3/

Doesn't work, no such file error. If

$ mkdir /home/user/TEST1/
$ mkdir /home/user/TEST1/TEST2/
$ mkdir /home/user/TEST1/TEST2/TEST3/

That work's, but I can't implement that solution. I need to use just one command.

Could you give me answer for this trouble?


You are looking for the -p argument:

-p, --parents 
no error if existing, make parent directories as needed

so the command you need is:

$ mkdir /home/user/TEST1/TEST2/TEST3/ -p
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.