zoukankan      html  css  js  c++  java
  • 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" ]
    then
        echo "${f} is a block (buffered) special file."
    else
        echo "${f} is not a block (buffered) special file."
    fi

    b) 检测 /dev/null 是否为字符设备文件。

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

    c) 检测 /etc 是否为目录。

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

    d) 检测 /etc/passwd 是否为普通文件。

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

    e) 检测 /bin/mail 是否为符合链接。

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

    f) 检测 /etc/passwd 是否可读。

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

    g) 检测 /etc/passwd 是否可写。

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

    h) 检测 /etc/passwd 是否可执行。

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

    i) 检测 /etc/passwd 是否存在。

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

    j) 检测 /etc/passwd 是否为空。

    f="/etc/passwd"
    if [ -s "$f" ]
    then
        echo "${file} is empty."
    else
        echo "${file} is not empty."
    fi
  • 相关阅读:
    图书馆管理系统
    php js_unescape correspond to js escape
    咖啡小驻搬家到此,感谢您继续关注本博
    OO系统分析员之路用例分析系列(1)什么是用例
    jquery tab 潇湘博客
    双色球中奖查询程序
    大象Thinking in UML早知道 001公告
    魔摸新学堂简介
    拙著《大象Thinking in UML》已在互动出版网http://www.chinapub.com/129881开始出售,12月1日全国各大书店有售,敬请关注!^_^
    jQuery进入微软和Nokia的解决方案 潇湘博客
  • 原文地址:https://www.cnblogs.com/huey/p/4906318.html
Copyright © 2011-2022 走看看