Create directory only if it is not already exist

2 Views
Reply
L
Legacy User 1
8/1/2019, 11:41:52 AM

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.

1 Reply

L
Legacy User 1
8/1/2019, 11:43:16 AM

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.

Leave a Reply

All replies are subject to pre-moderation. Your reply will appear publicly once approved.

S
SPYTM

Experience the pinnacle of digital communication. The ultimate ultra-premium platform designed for those who demand excellence.

© 2026 SPYTM. All rights reserved.