mkdir
stands for “make directory.” It’s a command used in Unix-like operating systems (including Linux and macOS) and also in Windows command-line environments. The purpose of the mkdir
command is to create directories (folders) within the file system.
Creating a directory
When you run mkdir
followed by the name of the directory you want to create, it will create that directory in the current working directory. The new directory will be created as a subdirectory of the directory you are currently working in.
Example
mkdir src
If you want to create a directory in a specific location other than the current working directory, you can provide the desired path before the directory name.
Example
mkdir ../src
Example
mkdir /home/matej/Documents/tmp/src
Creating multiple directories
You can also create a directory structure with the specified directories in a single command. In the following examples we will use three ways to create three directories named src, src/js, and src/css in one command.
Example
mkdir {src,src/js,src/css}
Example
mkdir src src/{js,css}
Example
mkdir src src/js src/css
All commands will create three directories named src
, src/js
, and src/css
in a single command.
src
├── js
└── css
You can achieve the same result with a single command using the -p
flag.
Example
mkdir -p src/js src/css
When you use the -p
flag, mkdir
will create all the necessary parent directories along with the specified directory.
Example
mkdir -p project/src/{js,css,assets}
Output
project
└── src
├── js
├── css
└── assets
Creating and Navigating
You can also create a directory and navigate into it using a single command.
Example
mkdir new-project && cd new-project
You’ve created a directory named “new-project
” and navigated into it. Now you’re ready to start working within your new project directory.
Example
mkdir -p project/src/{js,css,assets} && cd project/src