There are circumstances when we are required to make a tree of empty directories. If some intermediate directories exist in the given path, it will also have to incorporate checks to see whether the directory exists or not. It will make the code larger and inefficient. Let's see the use case and the recipe to solve the issue.
mkdir is the command for creating directories. For example:
$ mkdir dirpath
If the directory already exists, it will return a "File exists" error message, as follows:
mkdir: cannot create directory `dir_name': File exists
You are given a directory path (
/home/slynux/test/hello/child). The directory
/home/slynux already exist. We need to create rest of the directories