脚本如下
在Linux下直接执行即可:
#!/bin/bash
######################################################################
## ##
## 遍历指定目录获取当前目录下的二进制文件名(过滤掉原本代码) ##
## ##
######################################################################
##递归遍历
echo "script starting."
test_path="$1"
##过滤带后缀文件的列表
list=("c" "cc" "cpp" "java" "xml" "png" "mk" "ac" "h" "bp" "conf" "rc" "am" "txt" "jpg" "sh" "py" "json" "hal" "hpp" "aidl" "cfg" "dat" "mak" "ogg" "flags" \
"template" "key" "ext" "cer" "html" "gitignore" "wav" "js" "css" "zip" "config" "jpeg" "bmp" "acdb" "proto" "tlv" "pst" "der" "rst" "dts" "exe" "xsd" \
"in" "prefs" "classpath" "project" "idl" "min" "stm" "script" "dirs" "install" "db" "lm" "uim" "uimc" "properties" "qwsp" "pcm" "inl" "TXT" "jack" "sql" \
"list" "prop" "preloadspec" "m4a" "rs" "crt" "attr" "def" "Linux" "sdc" "idc" "gitattributes" "options" "pem" "crl" "clang-format" "bak" "dm" "md" "mk_" \
"suppress" "toc" "mht" "gmm" "yes" "docx" "ttf" "code")
length=${#list[@]}
# 过滤不带后缀的
list1=("LICENSE" "NOTICE" "Makefile" "README" "SConscript" "RELEASE_NOTES" "API_INFO" "AUTHORS" "CHANGES")
length1=${#list1[@]}
traverse_dir()
{
local filepath=$1
for file in `ls -a $filepath`
do
if [ -d ${filepath}/$file ]
then
if [[ $file != '.' && $file != '..' ]]
then
#递归
traverse_dir ${filepath}/$file
fi
else
#调用查找指定后缀文件
check_suffix ${filepath}/$file
fi
done
}
echo "script finished."
##获取后缀为so或jar或bin的文件
check_suffix()
{
file=$1
cnt=0
for val in ${list[@]}
do
if [ "${file##*.}"x != "$val"x ]
then
let cnt++
fi
done
if [ $cnt == $length ]
then
cnt1=0
for val in ${list1[@]}
do
if [ "${file##*/}"x != "$val"x ]
then
let cnt1++
fi
done
if [ $cnt1 == $length1 ]
then
echo $file >> ./result.txt
fi
fi
}
#需要统计的目录
traverse_dir ${test_path}