Recursively read folders and executes command on each of them

后端 未结 7 1650
执笔经年
执笔经年 2020-12-12 21:05

I am trying to recurse into folders and then run commands on them, using bash script. Any suggestions?

7条回答
  •  余生分开走
    2020-12-12 21:38

    Something like this should achieve your goal:

    function RecurseDirs
    {
        oldIFS=$IFS
        IFS=$'\n'
        for f in "$@"
        do
        -----your activity here-----
            if [[ -d "${f}" ]]; then
                cd "${f}"
                RecurseDirs $(ls -1 ".")
                cd ..
            fi
        done
        IFS=$oldIFS
    }
    

提交回复
热议问题