日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Shell - 文件运算符

發布時間:2024/9/5 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Shell - 文件运算符 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文件運算符

?文件運算符?描述
-b file?檢測 file 是否為塊設備文件
-c file?檢測 file 是否為字符設備文件?
-d file?檢測 file 是否為目錄
-e file?檢測 file 是否存在
-f file?檢測 file 是否存在為普通文件
-r file?檢測 file 是否可讀
-s file?檢測 file 是否為空文件
-w file?檢測 file 是否可寫
-x file?檢測 file 是否可執行
-L file?檢測 file 是否符號鏈接

?

實例

a) 檢測 /dev/sr0 是否為塊設備文件。

f="/dev/sr0" if [ -b "$f" ] thenecho "${f} is a block (buffered) special file." elseecho "${f} is not a block (buffered) special file." fi

b) 檢測 /dev/null 是否為字符設備文件。

f="/dev/null" if [ -c "$f" ] thenecho "${file} is a character (unbuffered) special file." elseecho "${file} is not a character (unbuffered) special file." fi

c) 檢測 /etc 是否為目錄。

f="/etc" if [ -d "$f" ] thenecho "${file} is a directory." elseecho "${file} is not a directory." fi

d) 檢測 /etc/passwd 是否為普通文件。

f="/etc/passwd" if [ -f "$f" ] thenecho "${file} is a regular file." elseecho "${file} is not a regular file." fi

e) 檢測 /bin/mail 是否為符合鏈接。

f="/bin/mail" if [ -L "$f" ] thenecho "${file} is a symbolic link." elseecho "${file} is not a symbolic link." fi

f) 檢測 /etc/passwd 是否可讀。

f="/etc/passwd" if [ -r "$f" ] thenecho "${file} is readable." elseecho "${file} is not readable." fi

g)?檢測 /etc/passwd 是否可寫。

f="/etc/passwd" if [ -w "$f" ] thenecho "${file} is writable." elseecho "${file} is not writable." fi

h)?檢測 /etc/passwd 是否可執行。

f="/etc/passwd" if [ -x "$f" ] thenecho "${file} is executable." elseecho "${file} is not executable." fi

i)?檢測 /etc/passwd 是否存在。

f="/etc/passwd" if [ -e "$f" ] thenecho "${file} is existent." elseecho "${file} is nonexistent." fi

j)?檢測 /etc/passwd 是否為空。

f="/etc/passwd" if [ -s "$f" ] thenecho "${file} is empty." elseecho "${file} is not empty." fi

?

轉載于:https://www.cnblogs.com/huey/p/4906318.html

總結

以上是生活随笔為你收集整理的Shell - 文件运算符的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。