递归更改Bash中的文件扩展名 [英] Recursively change file extensions in Bash

查看:63
本文介绍了递归更改Bash中的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想递归地遍历目录,并将某个扩展名的所有文件的扩展名更改,例如.t1更改为.t2. bash命令执行此操作是什么?

I want to recursively iterate through a directory and change the extension of all files of a certain extension, say .t1 to .t2. What is the bash command for doing this?

推荐答案

如果可以重命名,请使用:

If you have rename available then use:

find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' \;

如果重命名不可用,请使用:

If rename isn't available then use:

find . -name "*.t1" -exec bash -c 'mv "$1" "${1%.t1}".t2' - '{}' \;

这篇关于递归更改Bash中的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆