if [ -f "/path/dir/filename" ]; then # 檔案 /path/dir/filename 存在 echo"File /path/dir/filename exists." else # 檔案 /pat/dir/filename 不存在 echo"File /path/dir/filename does not exists." fi
檢查目錄是否存在:
1 2 3 4 5 6 7
if [ -d "/path/dir" ]; then # 目錄 /path/dir 存在 echo"Directory /path/dir exists." else # 目錄 /path/dir 不存在 echo"Directory /path/dir does not exists." fi