Linux make directory on command line

centos7

#1

So I know how to make one directory like:

mkdir my-dir-1
mkdir dir1 dir 2

What I need to know is how to make multiple directory using single mkdir command:

mkdir dir1/dir2 dir3/dir4

It always says:

mkdir: cannot create directory ‘dir1/dir2’: No such file or directory
mkdir: cannot create directory ‘dir3/dir4’: No such file or directory

How come it is not working? Can you help?`


#2

To create dir1/dir2, you need to create dir1 and dir1/dir2. The short cut way is

mkdir -p dir1/dir2 dir3/dir4

Where

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

#3

You can also throw it in a curly bracket

mkdir {dir1,dir2} 

this will make both directories in the same location.