문법

[ {parameter} {FILE 경로} ]
  • parameter
    • -e: 파일이 존재하면 true 리턴
    • -f: regular file이 존재하면 true 리턴
    • -r: 읽기 권한이 있는 파일이 존재하면 true 리턴
    • -w: 쓰기 권한이 있는 파일이 존재하면 true 리턴
    • -x: 실행 권한이 있는 파일이 존재하면 true 리턴
    • -d: 디렉토리가 존재하면 true 리턴

예시

FILE="$1"
 
if [ -f "$FILE" ];
then
   echo "File $FILE exist."
else
   echo "File $FILE does not exist" >&2
fi

참고 자료

https://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html