1、文件描述符
-e 判斷對象是否存在 -d 判斷對象是否存在,並且為目錄 -f 判斷對象是否存在,並且為常規文件 -L 判斷對象是否存在,並且為符號鏈接 -h 判斷對象是否存在,並且為軟鏈接 -s 判斷對象是否存在,並且長度不為0 -r 判斷對象是否存在,並且可讀 -w 判斷對象是否存在,並且可寫 -x 判斷對象是否存在,並且可執行 -O 判斷對象是否存在,並且屬於當前用戶 -G 判斷對象是否存在,並且屬於當前用戶組 -nt 判斷file1是否比file2新 [ "/data/file1" -nt "/data/file2" ] -ot 判斷file1是否比file2舊 [ "/data/file1" -ot "/data/file2" ]
2、示例
當前目錄下是否存在目錄jar
if [ -d "jar" ]; then echo "yes" else echo "no" fi
當前目錄下是否存在文件jar.sh
if [ ! -f "jar.sh" ]; then echo "yes" else echo "no" fi
附注:
[ ! -f "jar.sh" ]的[]的語法前后需要空格,否則會報錯