shell小脚本findinner搜索指定目录下文件
#!/bin/sh
#################################################
#created by ydds #
#date 2010-05-17 #
#function is findinner find string in file inner#
#################################################
[ $# -ne 2 ]&&echo "Usage: findinner /path string "&&exit 1
is_ignored_file() {
case "$1" in
*~ | *.tar | *.zip | *.gz | *.tar.gz| *.iso|*.rpm | *.gz| *.jpg| *.png|*.tar|*.zip|*.so)
return 0
;;
esac
return 1
}
i=1
echo;printf "|--------------------contains $2 string files------------------|\n"
for file in $(ls $1)
do
[ -d ${file} ]&&continue
is_ignored_file ${file}&&[ $? -eq 0 ]&&continue
num=$(sed -n "/$2/p" ${file}|wc -l)
[ $num -ge 1 ]&&printf "|\t${i}.$(echo ${file}|awk -F "/" '{print $NF}')\n"&&((i++))
done
[ $i -eq 1 ]&&echo "no files contains $2"
printf "|--------------------contains $2 string files------------------|\n";echo
本文出自 “一灯” 博客
相关新闻>>
- 发表评论
-
- 最新评论 更多>>