<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > Linux基礎系列之判斷符在shell中的使用方式

Linux基礎系列之判斷符在shell中的使用方式

作者: 時(shí)間:2012-07-25 來(lái)源:網(wǎng)絡(luò ) 收藏

1. 關(guān)于某個(gè)檔名的『類(lèi)型』偵測(存在與否),如 test -e filename

本文引用地址:http://dyxdggzs.com/article/148719.htm

-e 該『檔名』是否存在?(常用)

-f 該『檔名』是否為檔案(file)?(常用)

-d 該『文件名』是否為目錄(directory)?(常用)

-b 該『文件名』是否為一個(gè) block device 裝置?

-c 該『文件名』是否為一個(gè) character device 裝置?

-S 該『檔名』是否為一個(gè) Socket 檔案?

-p 該『檔名』是否為一個(gè) FIFO (pipe) 檔案?

-L 該『檔名』是否為一個(gè)連結檔?

2. 關(guān)于檔案的權限偵測,如 teST -r filename

-r 偵測該文件名是否具有『可讀』的屬性?

-w 偵測該檔名是否具有『可寫(xiě)』的屬性?

-x 偵測該檔名是否具有『可執行』的屬性?

-u 偵測該文件名是否具有『SUID』的屬性?

-g 偵測該文件名是否具有『SGID』的屬性?

-k 偵測該文件名是否具有『Sticky bit』的屬性?

-s 偵測該檔名是否為『非空白檔案』?

3. 兩個(gè)檔案之間的比較,如: test file1 -nt file2

-nt (newer than) file1 是否比 file2 新

-ot (older than) file1 是否比 file2 舊

-ef file2 與 file2 是否為同一檔案,可用在判斷 hard link 的判定上。 主要意義在判定,兩個(gè)檔案是否均指向同一個(gè) inode 哩!

4. 關(guān)于兩個(gè)整數之間的判定,例如 test n1 -eq n2

-eq 兩數值相等 (equal)

-ne 兩數值不等 (not equal)

-gt n1 大于 n2 (greater than)

-lt n1 小于 n2 (less than)

-ge n1 大于等于 n2 (greater than or equal)

-le n1 小于等于 n2 (less than or equal)

5. 判定字符串的數據

test -z string 判定字符串是否為 0 ?若 string 為空字符串,則為 true

test -n string 判定字符串是否非為 0 ?若 string 為空字符串,則為 false。

注: -n 亦可省略

test str1 = str2 判定 str1 是否等于 str2 ,若相等,則回傳 true

test str1 != str2 判定 str1 是否不等于 str2 ,若相等,則回傳 false

6. 多重條件判定,例如: test -r filename -a -x filename

-a (and)兩狀況同時(shí)成立!例如 test -r file -a -x file,則 file 同時(shí)具有 r 與 x 權限時(shí),才回傳 true。

-o (or)兩狀況任何一個(gè)成立!例如 test -r file -o -x file,則 file 具有 r 或 x 權限時(shí),就可回傳 true。

! 反相狀態(tài),如 test ! -x file ,當 file 不具有 x 時(shí),回傳 true

linux操作系統文章專(zhuān)題:linux操作系統詳解(linux不再難懂)


評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>