CIS120Linux Fundementals
mkdir Command
The mkdir
command in Linux is used to create directories. It is a straightforward command but comes with various options that allow for more advanced directory creation scenarios. Understanding how to use mkdir
effectively can help you organize your file system efficiently.
What the mkdir Command Does
The basic usage of the mkdir
command creates a single directory with the specified name. You can also create multiple directories at once or nested directories in one command.
Common Options for the mkdir Command
Here is a table of some of the most common options for the mkdir
command and their descriptions:
Option | Description |
---|---|
-p |
Create parent directories as needed |
-v |
Print a message for each created directory |
-m |
Set file mode (permissions) for the new directories |
--help |
Display help information about the mkdir command |
--version |
Output version information |
Examples
Creating a single directory:
This command creates a single directory named mydirectory
.
mkdir mydirectory
Creating multiple directories:
This command creates three directories named dir1
, dir2
, and dir3
.
mkdir dir1 dir2 dir3
Creating nested directories:
This command creates a nested directory structure. If the parent directories do not exist, the -p
option ensures they are created.
mkdir -p parent/child/grandchild
Verbose output:
The -v
option provides verbose output, confirming the creation of each directory.
mkdir -v mydirectory
Setting permissions while creating a directory:
This command creates a directory named mysecureddir
with permissions set to 755
(rwxr-xr-x).
mkdir -m 755 mysecureddir
Using the --help
option:
The mkdir --help command displays a help message detailing the usage, available options, and descriptions for the mkdir command. It provides a quick reference for users on how to create directories with different options.
mkdir --help
Output:
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-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
--help display this help and exit
--version output version information and exit
Conclusion
The mkdir
command is essential for creating directories in Linux. With its various options, you can create single or multiple directories, set specific permissions, and handle nested directories with ease. By practicing these commands and options, you will become proficient in managing directory structures in your Linux environment.