mkdir command tutorial in linux/unix with examples and use cases

linux mkdir command – make directories

Linux mkdir command is used to create directories. If the directory does not exist, it is created.

Syntax

 mkdir [OPTION]... DIRECTORY...

Options

  • -m, –mode=MODE
    set file mode (as in chmod), not a=rwx – umask
  • -p, –parents
    no error if existing, make parent directories as needed
  • -v, –verbose
    print a message for each created directory

Examples & Use Cases

Create multiple directories

In the following example we will create multiple directories under the current directory at the same time.

 ➜  mkdir dir-1 dir-2 dir-3

Create parent and child directory

In the following example, we are creating a multi-level directory, with both parent and child directories.

 ➜  mkdir -p parent/child

Create directory and set permissions

In the following example, directory permissions are set when the directory is created.

 ➜  mkdir -m 777 directory

Related post

Linux common commands tutorial and use examples
du command tutorial in linux/unix with examples and use cases
rmdir command tutorial in linux/unix with examples and use cases
touch command tutorial in linux/unix with examples and use cases
cd command tutorial in linux/unix with examples and use cases
pwd command tutorial in linux/unix with examples and use cases
ls command tutorial in linux/unix with examples and use cases
rm command tutorial in linux/unix with examples and use cases
df command tutorial in linux/unix with examples and use cases
Linux system directory structure

Add a Comment

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