Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find a particular directory in working directory in unix

Tags:

shell

unix

I want to check whether there exist directory named "name" in the current working directory. is it possible to do with ls?

   ls -l | grep ^-d

shows just directories but how to specify?

thanks in advance

like image 992
Adilli Adil Avatar asked Jan 14 '23 11:01

Adilli Adil


1 Answers

One should never parse the output of ls. If you are using bash, try this

if [ -d "$DIRECTORY" ]; then
  # will enter here if $DIRECTORY exists.
fi
like image 59
Fredrik Pihl Avatar answered Jan 30 '23 23:01

Fredrik Pihl