How To Make Directory In Linux?

Directories are used to store other directories or files in Linux and other operating systems. Directories can be created in different ways like File Managers, Command Line interfaces,s or applications. We can use the mkdir command in order to make a directory in Linux. The mkdir command can be used to create a single directory, multiple directories, parent/child directories, settings permissions, etc.

Make Directory with mkdir Command

We can use the mkdir command in order to make a directory. The directory name is provided to the mkdir command as a parameter. In the following example, we make the directory named “database”.

$ mkdir database

Make Multiple Directories

We can make multiple directories with the mkdir command. Every directory name is provided as a parameter to the mkdir command. The directory names are separated with spaces.

$ mkdir database users backups

If the directory names contain spaces double quotes can be used to prevent errors.

$ mkdir "my database" "my users" "our backups"

Make Parent and Child Directories

We can make multi-level directories or parent-child directories with the mkdir command providing the -p option.

$ mkdir -p database/mysql/current/

Make a Directory and Set Permissions

We can also set permissions during making the directory. The -m option is used to specify permissions for the newly created directory.

$ mkdir -m 722 backup

Leave a Comment