Linux mkdir command
The mkdir command used for creating new directories (also known as folder) on Unix/Linux systems. This is basic Linux command for creating the directory structure on a filesystem.
Syntax:
mkdir [OPTIONS] dir_name
Example
Let’s create a directory named testdir in the current directory. Run below from the command line.
mkdir testdir
The directory is created now. Use ls command to see the created directory.
Now create another directory inside some other directory by specifying the full path.
mkdir /var/www/testdir
In case any parent directory doesn’t exist, the above command will fail. You can use -p
option to create any parent directory if not exists.
mkdir -p /var/www/testdir
You can also specify the permission for the directory with mkdir command during the creation.
mkdir -m 777 testdir mkdir -m 755 testdir mkdir -m a=rwx testdir mkdir -m u=rwx,g=rw,o=r testdir
More Examples
Here are some more examples of mkdir command, which is useful for creating the directory structure.
Create two directories under /tmp directory in single command
mkdir -p /tmp/test1 /tmp/test
Now try the below command. This will do the same as above command do.
mkdir -p /tmp/{test1,test2}