shell 判断目录下是否有某文件

如题所述

第1个回答  2016-12-27
#!/bin/bash

if [ ! -f "$1" ];then
echo "当前目录不存在文件: $1"
else
echo "当前目录存在文件: $1"
fi
运行方法: ./test.sh filename (test.sh为脚本名称,filename为文件名称)
查找目录为当前目录;本回答被提问者和网友采纳
第2个回答  2016-12-27
if [ -f file ];then
    echo "this file is exist."
fi

第3个回答  2016-12-27
find ./ -name filename
第4个回答  2016-12-27
1、find $dir -type f|wc -l可以计算文件数量
2、实例
#!/bin/sh
dir=/opt/LNMP1
num=`find $dir -type f|wc -l`
if(( $num > 0 ));then
echo "$dir file number is:$num"
else
echo "$dir nofile"
fi

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网