虽说比较简单,但希望分享给大家。按需求改成想找的:例如txt,xls 等。
脚本名 扫描的路径 文件名
testFind.sh / testFind.txt (如果未配置环境变量 ./testFind.sh / testFind.txt 或sh 启动)
function find(){ for file in `ls $1` do if [ -d $1"/"$file ] then e $1"/"$file $2 else # echo -e $1"/"$file" " -> ${contentFile}"/"search_test.txt # if [ -e $1"/"$file ];then # echo $1/$file # echo "" # echo $1"/"$file >> ${contentFile}/search_test.txt # echo "${file}" -> $contentFile/search_test.txt # fi if [[ ${file} =~ "." ]];then if [ "${file##*.}"x = "jar"x ];then sub=${file%.*} # sedStr=${sub//-/_} version=${sub##*-} name=${sub%-*} # echo "${name}" if [[ $version == [0-9]* ]];then # csv文件是以“,”分割的文件,所以拼逗号 echo "$sysname","${name}","$version","${file}","$1","" >> $contentFile/$sysname.csv else echo "$sysname","${name}",,"${file}","$1","" >> $contentFile/$sysname.csv fi fi fi fi done } ###########################main#################### if [ $# -lt 2 ] then echo '请输入2个参数:[目标文件夹路径] , [系统英文名称] ' exit 3 fi echo " " echo "当前查询路径: $1" echo " " #当前执行的路径 contentFile=`pwd` #文件名 我们是按照系统统计的所以命名这个 sysname=$2 #判断文件是否存在 if [ -e $contentFile/$sysname.csv ];then rm -r $contentFile/$sysname.csv fi echo "" echo "[开始]搜索所有 *jar* 文件---- " echo "" find $1 $2 echo "[结束] 清查看jar文件清单:$contentFile/$2.csv" echo "" exit 0
--结果这样的