Shell - 文件运算符
生活随笔
收集整理的這篇文章主要介紹了
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." fib) 檢測 /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." fic) 檢測 /etc 是否為目錄。
f="/etc" if [ -d "$f" ] thenecho "${file} is a directory." elseecho "${file} is not a directory." fid) 檢測 /etc/passwd 是否為普通文件。
f="/etc/passwd" if [ -f "$f" ] thenecho "${file} is a regular file." elseecho "${file} is not a regular file." fie) 檢測 /bin/mail 是否為符合鏈接。
f="/bin/mail" if [ -L "$f" ] thenecho "${file} is a symbolic link." elseecho "${file} is not a symbolic link." fif) 檢測 /etc/passwd 是否可讀。
f="/etc/passwd" if [ -r "$f" ] thenecho "${file} is readable." elseecho "${file} is not readable." fig)?檢測 /etc/passwd 是否可寫。
f="/etc/passwd" if [ -w "$f" ] thenecho "${file} is writable." elseecho "${file} is not writable." fih)?檢測 /etc/passwd 是否可執行。
f="/etc/passwd" if [ -x "$f" ] thenecho "${file} is executable." elseecho "${file} is not executable." fii)?檢測 /etc/passwd 是否存在。
f="/etc/passwd" if [ -e "$f" ] thenecho "${file} is existent." elseecho "${file} is nonexistent." fij)?檢測 /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 - 文件运算符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表格行内编辑增删改查
- 下一篇: 九度OJ 1168:字符串的查找删除 (