Linux check if a directory exists

 

To check if a directory exist or not use following script:

#!/bin/bash
FILE_NAME=$1

if [ -f $FILE ];
then
   echo "File $FILE_NAME exists" 
else 
   echo "File $FILE_NAME does not exists" 
fi

You can also use following one liner to do same validation:

$ [ -d /usr/share ] && echo "Directory exists" || echo "Directory does not exists"

-Sany

About these ads

One comment on “Linux check if a directory exists

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s