Linux mkdir command

Linux mkdir command

 Linux mkdir command

The mkdir command is used for creating new directories (also known as folders) on Unix/Linux systems. This is basic Linux command for creating the directory structure on a filesystem.


mkdir [OPTIONS] dir_name


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 the ls command to see the created directory.

ow, 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 the 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 a single command

mkdir -p /tmp/test1 /tmp/test

Now try the below command. This will do the same as the above command do.

mkdir -p /tmp/{test1,test2}

Post a Comment