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: |
|||||
|
|
|||||||
|
|
|||
|
|
Assuming your shell is BASH:
|
|||
|
|
[ -d "YOUR_DIR" ] && echo "is a dir" e.g.:
echos: root dir. |
|||||
|
|
The canonical way is to use the test(1) utility:
where "path" is the pathname of the directory in question. |
|||
|
|