脚本检查文件存在

这个问题在这里已经有了答案:

  • 如何判断Bash中是否存在常规文件? 17个答案

  • 如果您的文件处于当前路径本身,则无需使用find ,以下可帮助您。

    #!/bin/bash
    filename=$1
    if [[ -f "$filename" ]]; then
            echo "file exists"
    else
            echo "file does not exists"
    fi
    

    然后以script.ksh file_name运行脚本如果您需要验证文件是否存在并且具有某种大小,则在上面的代码中将-f更改为-s

    你也可以在你的盒子里进行man test来检查所有这些情况。

    链接地址: http://www.djcxy.com/p/24125.html

    上一篇: script checking file exists

    下一篇: does file exist?