Basic Usage
The basic command format is:
bashmkdir [options] directory_name
Here, "directory_name" can be any name you want to create. If the directory name contains spaces, enclose it in quotes.
Examples
- Creating a single directory:
bashmkdir mydirectory
This command creates a new directory named mydirectory in the current working directory.
2. Creating multiple directories:
bashmkdir dir1 dir2 dir3
This command creates three directories: dir1, dir2, and dir3.
3. Creating multi-level directories:
bashmkdir -p parent/child/grandchild
Using the -p option ensures that all necessary parent directories are created when creating grandchild, even if they did not exist previously.
Advanced Options
-p(parents): As previously mentioned, this option allows creating multi-level directory structures, ensuring that all specified parent directories are created if they do not exist.-m(mode): Allows users to specify directory permissions. For example:mkdir -m 755 newdircreates a directory that is readable and executable by all users but writable only by the owner.
Use Cases
In software development, you may need to create specific directory structures to store code, test files, logs, etc. For example, when initializing a new project, you need to create many folders for different purposes, making the mkdir command very useful.