linux文件夹下递归执行脚本/程序

在linux中,若需要使用某个脚本/程序对文件夹下所有符合条件的文件执行,可采用如下方法:

 

首先是find命令,用find找出符合条件的待执行文件/文件夹

## 只列出常规文件
find ./ -type f 
## 只列出文件夹
find ./ -type d
## 列出后缀cpp的文件
find -name *.cpp

 

对找到的所有文件批处理

find ./ -type f -exec chmod 644 {} \; # 后面的\;必须的,表示按行输出
find ./ -type d -exec chmod 755 {} \; # {} 表示找到的文件路径

find ./ -type f -exec ./dos2unix {} \ # 对所有文件执行dos2unix脚本

 

posted @ 2018-02-22 16:42  Jarvis_Xu  阅读(585)  评论(0编辑  收藏  举报