歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Unix中test命令的用法

Unix中test命令的用法

日期:2017/2/28 15:55:57   编辑:Linux教程

test命令的功能:檢查文件和比較值。

1、判斷表達式

if test (表達式為真)

if test !(表達式為假)

test 表達式1 -a表達式2兩個表達式都為真

test 表達式1 -o表達式2兩個表達式有一個為真

2、

test -n 字符串字符串的長度非零

test -z 字符串字符串的長度為零

test 字符串1=字符串2字符串相等

test 字符串1!=字符串2字符串不等


3、判斷整數

test 整數1 -ep 整數2整數相等

test 整數1 -ge 整數2整數1大於等於整數2

test 整數1 -gt 整數2整數1大於整數2

test 整數1 -le 整數2整數1小於等於整數2

test 整數1 -lt 整數2整數1小於整數2

test 整數1 -ne 整數2整數1不等於整數2

4、判斷文件

test File1 -ef File2兩個文件具有同樣的設備號和結點號

test File1 -nt File2文件1比文件2新

test File1 -ot File2文件1比文件2舊

test -b File文件存在並且是塊設備文件

test -c File文件存在並且是字符設備文件

test -d File文件存在並且是目錄

test -e File文件存在

test -f File文件存在並且是正規文件

test -g File文件存在並且是設置了組ID

test -G File文件存在並且屬於有效組ID

test -h File文件存在並且是一個符號鏈接(同-L)

test -k File文件存在並且設置了sticky位

test -b File文件存在並且是塊設備文件

test -L File文件存在並且是一個符號鏈接(同-h)

test -o File文件存在並且屬於有效用戶ID

test -p File文件存在並且是一個命名管道

test -r File文件存在並且可讀

test -s File文件存在並且是一個套接字

test -t FD 文件描述符是一個終端打開的

test -u File文件存在並且設置了它的set-user-id位

test -w File文件存在並且可寫

tes -x File文件存在並且可執行

Copyright © Linux教程網 All Rights Reserved