반응형

간단한건데 해당 옵션을 모르면 헤메는 경우가 있어 기왕 관련 작업한거 정리해보려 한다.

일반적으로 쉘스크립트에서 파일이 존재하는지 확인하고 싶다면 아래처럼 사용하면 된다.

if[ -e $FileName ]; then
	echo "file exist"
else
	echo "file not exist;
fi

주요 옵션 몇개만 살펴보자면

-c : 파일이 존재하고 특수문자가 있는지 체크 (File exists and is character special)

-e : 파일이 존재 하는지 체크 (File exists)

-d : 파일이 존재하고 파일이 폴더인지 체크 (File exists and is a directory)

-f : 파일이 존재하고 보통 파일인지 체크 (File exists and is a regular file)

-h : 파일이 존재하고 symbolic link 파일인지 확인 (File exists and is a symbolic link (same as -L)

-r : 파일이 존재하고 read 가능한 파일인지 확인 (File exists and read permission is granted)

-w : 파일이 존재하고 쓰기 가능한 파일인지 확인 (File exists and write permission is granted)

-s : 파일이 존재하고 0size 파일이 아닌지 체크 (File exists and has a size greater than zero)

 

반응형
반응형

쉘 스크립트를 사용하다보면 스크립트 중간에 그 다음 로직으로 넘어가기전 특정 시간동안 멈추고 싶을 경우가 있다.


그럴 경우 다음과 같이 원하는 시간만큼 간편히 sleep 시킬 수 있다.


[ shell script 간편 sleep 포맷 ]

sleep .5 # Waits 0.5 second.

sleep 5  # Waits 5 seconds.

sleep 5s # Waits 5 seconds.

sleep 5m # Waits 5 minutes.

sleep 5h # Waits 5 hours.

sleep 5d # Waits 5 days.


반응형

+ Recent posts