Is mkdir -p totally safe when creating folder already exists

mkdir -p would not give you an error if the directory already exists and the contents for the directory will not change.

Manual entry for mkdir


A portable script will rely upon POSIX, which says of mkdir's -p option:

Each dir operand that names an existing directory shall be ignored without error.

and if there are no errors reported, the -p option has done its job:

Create any missing intermediate pathname components.


mkdir WILL give you an error if the directory already exists.

mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.

Tags:

Mkdir