Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»Mkdir Command in Linux with Examples

    Mkdir Command in Linux with Examples

    RahulBy RahulJune 29, 20173 Mins ReadUpdated:July 5, 2021

    mkdir (make directory) is the basic command for Unix-like systems for creating a directory in the file system. This is the frequently used command by Unix/Linux system users. If you are are Linux system user, you must be aware of this command.

    This tutorial described to you how to create a directory on Unix/Linux-based systems along with various available options. Let’s discuss the Linux mkdir command with useful examples.

    • Linux cd Command Help and Examples

    Syntax

    mkdir [OPTION]... DIRECTORY...
    

    Create a New Directory in Linux

    Use mkdir followed by the directory name to be created under the current directory.

    mkdir newdir 
    

    You can also create a directory under another directory by providing the absolute or relative path.

    mkdir /opt/newdir
    

    mkdir Command Examples

    Here are some more useful examples of mkdir command on Unix/Linux systems.

    1. Create directory in present working directory – Use the following command to create directory in present working directory. Just use the mkdir command followed by the directory name to be created.
      mkdir newdir 
      
    2. Create directory including parent directory – When creating a directory at other location, the parent directories must be available. If the parent directories are not available it will through error with the above examples.

      But the mkdir command provides an option to also create parent directories.

      mkdir -p /opt/backup/newdir 
      

      Here the -p tells mkdir to also create parrent directories well.

    3. Creating multiple directory in single command You can also created multiple directories in a single command.
      mkdir {dir_1,dir_2,dir_3} 
      

      You can also ass all the directory names including paths to create multiple directories in a single command.

      mkdir  dir_1 /backup /srv/www 
      
    4. Create directory with parent directory – The default mkdir command will return error if any parent directory doesn’t exits. But you can use the “-p” option to instruct the mkdir command to create any parent directory if not exists.
      mkdir -p /var/www/folder1/public 
      
    5. Create directory with specific permissions – Use -m option to to set default permission to a directory during creation time. This is similar to create directory and change permission with chmod command.
      mkdir -m 644 dir1  
      mkdir -m a=rwx dir1 
      mkdir -m u=rw,g=r,o=r dir1 
      
    6. Create multiple directories at specific location – This is very lesser known option for creating multiple directories on different location with single command. The following command will create directories named one, two, three under the mydir directory.
      mkdir -p ./newdir/{one|two|three} 
      

    Conclusion

    In this tutorial, you have learned about the mkdir command in Linux with examples. If you have any other useful examples, please do share in the comments and we will include them in this tutorial.

    mkdir mkdir command
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Convert PPK to PEM file using Command
    Next Article What is Authoritative and Non-authoritative DNS Server

    Related Posts

    Running Multiple Commands At Once in Linux

    Updated:August 6, 20223 Mins Read

    Convert String to Lowercase in Bash – Easier Than You Think

    Updated:August 1, 20221 Min Read

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    tee Command in Linux with Examples

    Updated:July 1, 20224 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.