Table of Contents Introduction Redhat recently introduced the System Storage Manager (SSM), a unified user interface that allows uses to manage complicated systems in a
In this article, we’ll cover the mkdir command, which stands for make directories, and review basic mkdir command examples.
David Mackenzie authored the mkdir command found in the GNU coreutils package, as documented in the Linux Manual pages. This command, originating in the 1970s, has become ubiquitous across various operating systems, including Linux, DOS, Microsoft Windows, IBM, and OS/2. Its enduring presence underscores its versatility and widespread adoption beyond just Linux environments.
It is not uncommon to use the mkdir command when performing Linux-related procedures. For example, a recent SSM article we posted some days ago (as of the date of this publication), required that we create a directory in order to mount a logical volume.
The article about Installing and Using Git in Linux also requires the use of the mkdir command at some point in the procedure.
Let’s go over a few basic mkdir command examples.
This command will create a parent directory if it doesn’t exist. If the directory exists it will not throw an error. For example, a command like (below) will generate an error because the testparent and test1 directories don’t exist:
$ mkdir testparent/test1/test2
mkdir: cannot create directory ‘testparent/test1/test2’: No such file or directory
However, when we execute the same command with the -p option, both testparent and test1 directories are created as well along with test2 (as shown in the image below).
Photo by admingeek from Infotechys
$ mkdir -v testparent/test1/test2/test3
mkdir: created directory ‘testparent/test1/test2/test3’
In the above example, we created another sub-directory under testparent/test1/test2 called test3.
To check the version of mkdir installed on our machine, we run the mkdir command with the –version option.
$ mkdir --version
mkdir (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.
The -m option, which sets the file modes, is used with the mkdir command, when we want to specify permissions or user access to a certain directory or directories.
In the screenshot below, we created yet another sub-directory under testparent/test1/test2/test3 and passed to it the -m option along with the a=rwx. This grants read, write, and execute permissions to the test4 sub-directory to all users.
Photo by admingeek from Infotechys
To create multiples directories in given location of the directory tree, we execute the mkdir command using the curly brackets.
The following command while create subtest1, subtest2, and subtest3 sub-directories under the testparent/test1 parent directory.
$ mkdir testparent/test1/{subtest1,subtest2,subtest3}
[admin@vm4-dev-infotechys ~]$ ls -l testparent/test1
total 0
drwxrwxr-x. 2 admin admin 6 Feb 5 03:14 subtest1
drwxrwxr-x. 2 admin admin 6 Feb 5 03:14 subtest2
drwxrwxr-x. 2 admin admin 6 Feb 5 03:14 subtest3
drwxrwxr-x. 3 admin admin 19 Feb 5 02:12 test2
NOTICE: The sub-directories are separated by commas and no spaces.
With its straightforward syntax and indispensable functionality, mkdir exemplifies the elegance and efficiency of Unix-like commands. Whether you’re a seasoned sysadmin or a curious enthusiast, mastering the art of mkdir opens doors to effective file management and organization across a myriad of computing platforms.
Was this article informative or helpful to you? If so, leave us a comment below and share!
Related Posts
Table of Contents Introduction Redhat recently introduced the System Storage Manager (SSM), a unified user interface that allows uses to manage complicated systems in a
In this article, we will review the most commonly used RPM commands in Linux. These commands play a pivotal role in package management, allowing users
Table of Contents Introduction According to the Linux manual pages (man yum), there are 35 standard YUM commands. That number increases to the hundreds when