PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 服务器 > Linux教程 > 正文

    linux shell脚本遍历当前目录下及子目录符合要求文件

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:遍历整个文件夹及子目录。将所有mpg格式的文件及其路径保存到记事本a.txt中。#!/bin/bashfunction ergodic(){for file in ` ls $1`do...
     遍历整个文件夹及子目录。将所有mpg格式的文件及其路径保存到记事本a.txt中。
    #!/bin/bash
    function ergodic(){
    for file in ` ls $1`
    do
                     if [ -d $1"/"$file ]
                     then
                           ergodic $1"/"$file
                     else
                           local path=$1"/"$file #得到文件的完整的目录
                           local name=$file       #得到文件的名字
                           #做自己的工作.
                        if [ "${file##*.}" = "mpg" ]; then
                                              echo $1"/"$file >>a.txt
                                        
                       fi
                    fi

    done
    }
    INIT_PATH="."
    ergodic $INIT_PATH
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-121-1511-1.html
    相关热词搜索: