How to check if a directory exists in Linux command line?
Solution: [ -d ¨a¨ ]&&echo ¨exists¨||echo ¨not exists¨
|
How to check if a directory exists in Linux command line? Solution: | |||||
feedback
|
This question came from our site for professional and enthusiast programmers.
| |||||||
feedback
|
| |||
feedback
|
|
Assuming your shell is BASH:
| |||
feedback
|
|
The canonical way is to use the test(1) utility:
where "path" is the pathname of the directory in question. | |||
|
feedback
|
|
[ -d "YOUR_DIR" ] && echo "is a dir" e.g.:
echos: root dir. | |||||
feedback
|