Create directory on...
 

Create directory only if it is not already exist

2 Posts
1 Users
0 Reactions
1,178 Views
Avatar of admin
(@mjv119gmail-com)
Estimable Member Admin
Joined: 10 years ago
Posts: 79
Topic starter  

Often we use to create a folder in a directory which contains lot of sub directories. When we try to create a directory, we will get the below error message if that directory is already present.

mkdir: Failed to make directory “test”; File exists

I want to know how to hide the above error message and to create folder only if its not already exist. If its already exist then it should ignore that folder.

This topic was modified 5 years ago 2 times by admin

   
ReplyQuote
Avatar of admin
(@mjv119gmail-com)
Estimable Member Admin
Joined: 10 years ago
Posts: 79
Topic starter  

Use -p option with mkdir command. This will omit if that directory is already present.

mkdir -p dir

It will not threw error message even that directory is already present. It will ignore that directory.


   
ReplyQuote

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: