Tuesday, May 10, 2011

How to check directory/file exists in shell script

Check file exists code snippet

FILE_TO_CHECK="/path/to/myfile"


if [-f $FILE_TO_CHECK]; then 
......
do something here
......
fi 


Check directory exists code snippet

DIR_TO_CHECK="/path/to/my/dir"

if [-d $DIR_TO_CHECK]; then 
......
do something here
......
fi 



No comments:

Post a Comment