The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem when test to see if directory exists trivektor Shell Programming and Scripting 3 08-11-2008 10:48 PM
How can I check if directory exists in a makefile zivsegal UNIX for Dummies Questions & Answers 2 09-10-2007 12:12 AM
how to check if masked directory exists? philplasma Shell Programming and Scripting 4 05-30-2007 05:46 PM
rm: Unable to remove directory xxxx/xxxx: File exists deejay UNIX for Dummies Questions & Answers 1 11-06-2005 09:17 PM
check if directory exists jerardfjay Shell Programming and Scripting 2 06-13-2005 11:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-11-2006
tez tez is offline
Registered User
 

Join Date: Aug 2006
Posts: 11
Directory exists

Hi all,

Sorry about this i'm sure this is a very silly question hence an easy answer but:

I'm trying to write a script, part of which I want to check if a directory exists, if it doesn't then create it.

Thanks for your help
Tez
Reply With Quote
Forum Sponsor
  #2  
Old 08-11-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
-d option

search the forum.
Reply With Quote
  #3  
Old 08-11-2006
Supporter
 

Join Date: Jul 2006
Posts: 156
From the manual for 'test':
Code:
[(1)                             User Commands                            [(1)

NAME
       test - check file types and compare values

SYNOPSIS
       test EXPRESSION
       [ EXPRESSION ]
       [ OPTION

       -d FILE
              FILE exists and is a directory

       -e FILE
              FILE exists
So,
Code:
MY_DIR="ZZZ"
if [ ! -d $MY_DIR ] ; then
  mkdir $MY_DIR
fi
Of course this will still fail if MY_DIR exists but is something other than a directory. So to prevent that you would use the -e option instead of -d.
Reply With Quote
  #4  
Old 08-11-2006
tez tez is offline
Registered User
 

Join Date: Aug 2006
Posts: 11
That works thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0