重命名子目录中的文件名

时间:2013-11-27 14:17:15

标签: macos terminal

我正在使用以下内容来整理文件名。

    for f in *; do mv "$f" "${f//remove/replace}"; done 

我如何使用此解决方案或类似解决方案递归处理一堆子目录?

1 个答案:

答案 0 :(得分:2)

有几种选择,这是我的最爱:

find <the-path> <the-criteria> | while read file; do mv $file <$file-renamed>; done

例如:

find . -name "*.jpg" | while read file; do mv "$file" "`echo $file | sed -e 's/jpg/png/'`"; done

使用sed或构建替换名称所需的任何工具。

相关问题