Linux的判斷命令

來源:互聯網
上載者:User

標籤:系統   image   ima   lin   ons   eee   ssi   運行   type   

1. test

① 作用:檢測系統中某些屬性和檔案是否存在。

② 簡單的案例

test -e /eeee && echo "exist" || echo "not exist"  判斷系統中 /eeee 是否存在 存在輸出exist 不存在測輸出 not exist

③ 參數說明

 ④案例

#!/bin/bashecho -e "Please input a filename, I will check the filename  type and permission\n\n"read -p "Input a filename:" filename# 判斷是否輸入了的檔案名稱,如果沒有輸入了就停止運行# test -z $filename 判斷filename是否為空白字串test -z $filename && echo "You Must input a filename" && exit 0# 如果檔案不存在 # test -e 判斷檔案存在 ! 表示相反test ! -e $filename && echo "The filename ‘$filename‘ DO NOT exist" && exit 0# 判斷檔案是檔案還是目錄test -f $filename && filetype="regulare file"test -d $filename && filetype="directory"# 判斷檔案對於目前使用者的許可權(讀、寫、執行)test -r $filename && perm="readable"test -w $filename && perm="$perm writable"test -x $filename && perm="$perm executable"echo "The filename: $filename is a $filetype"echo "And the permissions are: $perm"

  

Linux的判斷命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.