1753768 Members
5947 Online
108799 Solutions
New Discussion юеВ

Directory Exist or not

 
Karthick K S
Frequent Advisor

Directory Exist or not

how to check if directory exist or not

for eg: /home/example/test/

i want to check test directory exist in /home/example/ if not eror wil be come
3 REPLIES 3
Arunvijai_4
Honored Contributor

Re: Directory Exist or not

Why don't you use
# ls -ld /home/example/test/
/home/example/test/ not found

-Arun

"A ship in the harbor is safe, but that is not what ships are built for"
Pete Randall
Outstanding Contributor

Re: Directory Exist or not

if [ `ls -ld /dirname | wc -l` -ne 1 ]
then
echo "/dirname does not exist"
fi


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: Directory Exist or not

Hi:

# [ -d /home/example ] && echo "Directory exists" || echo "No Directory"

See the manpages for 'test'.

Regards!

...JRF...