#!/bin/bash
if [ ! -f "$1" ];then
echo "当前目录不存在文件: $1"
else
echo "当前目录存在文件: $1"
fi
运行方法: ./test.sh filename (test.sh为脚本名称,filename为文件名称)
查找目录为当前目录;
if [ -f file ];then
echo "this file is exist."
fi
find ./ -name filename
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