Shell Script 파일 체크

0_0ni·2023년 3월 3일

기본 문법

if [ -f "$FILENAME" ]; then
	echo "file exist"
else 
	echo "file not exist"
fi

옵션

  • -b FILE
    파일이 존재하고 특별한 파일인지 체크
    FILE exists and is block special
  • -c FILE
    파일이 존재하고 특수문자가 있는지 체크
    FILE exists and is character special
  • -d FILE ; 디렉토리 여부 확인
    파일이 존재하고 그 파일이 폴더인지 체크
    FILE exists and is a directory
  • -e FILE ; 파일과 폴더 구분 없이 존재하는지 확인
    파일이 존재하는지 체크
    FILE exists
  • -f FILE ; 파일 유무 및 보통 파일 확인
    파일이 존재하고 보통 파일인지 체크
    FILE exists abd is a reqular file
  • -g FILE
    파일이 존재하고 group ID로 설정되었는지 체크
    FILE exixsts and is set-group-ID
  • -G FILE
    FILE exists and is owned by the effective group ID
  • -h FILE
    파일이 존재하고 symbolic link 파일인지 확인
    FILE exists and is a symbolic link (same as -L)
  • -k FILE
    FILE exists and has its sticky bit set
  • -L FILE
    파일이 존재하고 symbolic link 파일인지 확인
    FILE exists and is a symbolic link (same as -h)
  • -O FILE
    파일이 존재하고 owner가 유효한지 확인
    FILE exists and is owned by the effective user ID
  • -p FILE
    파일이 존재하고 그 파일이 pipe인지 확인
    FILE exists and is a named pipe
  • -r FILE
    파일이 존재하고 read 가능한 파일인지 확인
    FILE exists and read permission is granted
  • -s FILE
    파일이 존재하고 0 size 파일이 아닌지 체크
    FILE is exists and has a size greater than zero
  • -S FILE
    파일이 존재하고 그 파일이 소켓인지 확인
    FILE eixsts and is a socket
  • -t FD file descriptor FD is opened on a ternimal
  • -u FILE
    FILE exists and its set-user-ID bit is set
  • -w FILE
    파일이 존재하고 쓰기 가능한 파일인지 확인
    FILE exists and write permission is granted
  • -x FILE
    파일이 존재하고 실행 가능한 파일인지 확인
    FILE exists and execute (or search) permission is granted

참고: https://foris.tistory.com/256

0개의 댓글