mkdir makes a directory at each path that you give it:
text
learner@tidepool:~/shop$ mkdir archive
learner@tidepool:~/shop$ mkdir january february marchThe second line makes three directories, next to each other.
The directories above must exist
Without a flag, mkdir makes only the last name in the path:
text
learner@tidepool:~$ mkdir web/releases/v1
mkdir: cannot create directory 'web/releases/v1': No such file or directoryweb and web/releases do not exist, so mkdir stops.
-p: make the full path
The flag -p makes each missing directory in the path, from left to right:
text
learner@tidepool:~$ mkdir -p web/releases/v1- web← made
- releases← made
- v1← made
A directory that already exists
| Line | archive exists | archive does not exist |
|---|---|---|
mkdir archive | Error: File exists | Makes it |
mkdir -p archive | No error. Nothing changes | Makes it |