Find a specific directory in the working directory on unix

I want to check if a directory named "name" exists in the current working directory. is it possible to do this with ls?

ls -l | grep ^-d 

shows only directories, but how to specify?

early

+4
source share
4 answers

Do not parse the output of ls . If you are using bash try this

 if [ -d "$DIRECTORY" ]; then # will enter here if $DIRECTORY exists. fi 
+3
source

This is the -d test. Just:

 if [ -d "name" ]; then echo "yay!" else echo "nay!" fi 
+3
source
 test -d 'name' && echo "It is there" 

test -d 'name' can be used in if statements, etc.

+2
source

Try it?

 ls -l | grep ^d name 
+1
source

Source: https://habr.com/ru/post/1479002/


All Articles