[Unix] Command to create directory only if it does not exist

mkdir is a very useful legacy command that comes bundles with Unix as well as Windows. We can create directory trees, set permissions etc.

The -p option with mkdir can be used to determine if the directory is already present and create it if it does not exist.

$ mkdir -p /home/demo /sub2/Test

     The -p flag creates the /home, /home/demo, and /home/demo/sub2 directories
     if they do not already exist.

However, if the directories already exists, the command does nothing.

No comments :

Post a Comment