• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

mkdir command in Linux with Examples

Written by Rahul, Updated on December 10, 2020

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

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

  • Linux cd Command Help and Examples

Syntax

mkdir [OPTION]... DIRECTORY...

Create Directory in Linux

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

mkdir mydir 

You can also create directory at other location by providing complete path.

mkdir  /opt/mydir

mkdir Command Examples

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

  1. Create directory in current directory – Use the following command to create directory in present working directory. Just use mkdir command followed by the directory name to be created.
    mkdir newdir 
    
  2. Create directory at other location – You can also use absolute or related directory path to create a directory inside a other directory. Like:

    The following command will create a directory named backup under the /opt/files directory:

    mkdir /opt/files/backup 
    

    You can also use relative path while crating directory. For example, the belwo command will create directory under the files directory available in present working directory.

    mkdir files/backup 
    
  3. Creating multiple directory – You can also created multiple directories in a single command. Just pass all the directory names including path for directories at other locations.
    mkdir dir1 dir2 /opt/dir3 
    
  4. Create directory with parent directory – The default mkdir command will return error if any parent directory doesn’t exits. But you use “-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 mydir/{one|two|three} 
    

Conclusion

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

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy