Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test for Directory

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

Using the Bourne shell on a Solaris 8 system how can I test if a directory exists or not?

I want to test for /z and if it does not exist creat it.

Thanks,

Michael42
 
man test

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Michael:

the unix mkdir command has a -p option that will create all the directories if they don't already exist. That's probably just as efficient as checking if the directory already exists.

Regards,


Ed
 
you could use the find command

ex..

find / -name "dirname or filename" -print

this says find from the root directory down, any file or directory with the name you give and print to the screen.
this will give you the full path.

hope this helps

CA
 
Thanks all - great suggestions!

Thanks,

Michael42
 
DIR=/path_to_dir

if [ -d $DIR ]; then echo "Is a Dir"; fi

or use [ -e ] for exists



>---------------------------------------Lawrence Feldman
SR. QA. Engineer SNAP Appliance
lfeldman@snapappliance.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top