how to use mkdir command

How to use mkdir Command?

The “Make Directory” command in Linux creates a new directory in the file system. Using mkdir command also configures the permissions on newly created directories as well as to construct directories, including nested directories.

Example Code

mkdir [directory]

Where directory is the path of the directory that you want to create.

use of mkdir command
Note: Using “mkdir howto” command creates a new directory “howto”.

Special Note:

As you will see in all of the example images we have been using“ls” command. To know more click the link below.

How to Use ls command?

Mkdir command available options

  • -p: If the parent directories don’t already exist, you can create them with the -p option. For instance, the -p option will construct the “docs” directory before establishing the “project1” directory if you want to build the directory howto/docs/project1 but the documents directory does not already exist.
use of mkdir command with -p option
Note: “mkdir -p howto/docs/project1” creates all the necessary directories that does not exist. In the example we have created three directories all at once. “howto” with sub directory “docs” and “project1” at the end.
  • -m: The new directory’s permissions can be set with the -m option. It accepts an octal number as a parameter, which stands for the directory’s permissions. For instance, the command mkdir -m 755 new directory will create a new directory with the owner’s read, write, and execute permissions as well as the group’s and others’ read and execute capabilities.
Using mkdir command with -m option
Note: “mkdir -m 777 offsecpath” assign permission to the newly created directory.

Special Note

We have set the permission to “777”. To know more about file and folder permission click the link below.

How to use chmod command?

  • -v: Use the -v option to show verbose output. It will display the command’s status along with the name of the newly formed directory.
Use of mkdir command with -v flag
Note: As seen above “mkdir howto” creates a directory without any information. But “mkdir -v directory” creates a folder while giving the information what has been done.

When you need to create a new directory, either to store files or to manage existing files, you frequently use the mkdir command. When you need to construct nested directories and change the permissions on the newly generated directories, the -p and -m arguments come in handy.

It’s important to note that if you don’t specify any permissions while creating a new directory, the default permissions will be applied. The umask value of the user, which governs the file permission for new files and directories, affects the default permissions in several ways.

1 thought on “How to use mkdir Command?”

  1. bustyvixennicole

    Itís hard to find knowledgeable people for this subject, but you seem like you know what youíre talking about! Thanks

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top