Bash Make Directory
mkdir creates new directories, and its -p flag lets you create a whole nested folder structure in a single command.
Creating a Single Directory
mkdir takes one or more names and creates a new, empty directory for each one in the current location. If a directory with that name already exists, mkdir refuses and prints an error rather than silently doing nothing.
Create one folder
$ mkdir photos
$ ls -l
drwxr-xr-x 2 user user 4096 Jul 16 10:05 photosCreating Several Directories at Once
List multiple names to create several sibling directories in one call. This is handy for setting up a standard project layout in a single step.
Create a project skeleton
$ mkdir src tests docs
$ ls
docs src testsCreating Nested Paths with -p
Without -p, mkdir fails if any parent directory in the path is missing. The -p (parents) flag creates every missing directory along the path automatically, and it also stays silent instead of erroring if the final directory already exists — which makes it safe to rerun in scripts.
Create a deep path in one command
$ mkdir -p project/src/components/auth
$ find project -type d
project
project/src
project/src/components
project/src/components/auth- mkdir name — create one directory
- mkdir a b c — create several directories at once
- mkdir -p a/b/c — create a nested path, making parents as needed
- mkdir -p existing_dir — succeeds quietly even if the directory is already there
- mkdir -v name — print a message confirming each directory created