在文件中查找一个模式,将其重命名 [英] find a pattern in files and rename them

查看:115
本文介绍了在文件中查找一个模式,将其重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个命令来查找与给定模式的文件,然后将其重命名为其他

I use this command to find files with a given pattern and then rename them to something else

find . -name '*-GHBAG-*' -exec bash -c 'echo mv $0 ${0/GHBAG/stream-agg}' {} \;

当我运行此命令,我看到一些输出,这样

As I run this command, I see some outputs like this

mv ./report-GHBAG-1B ./report-stream-agg-1B
mv ./reoprt-GHBAG-0.5B ./report-stream-agg-0.5B

不过在最后,当我运行 LS ,我看到旧的文件名。

推荐答案

您echo'ing你的MV命令,而不是实际执行它。更改为:

You are echo'ing your 'mv' command, not actually executing it. Change to:

find . -name '*-GHBAG-*' -exec bash -c 'mv $0 ${0/GHBAG/stream-agg}' {} \;

这篇关于在文件中查找一个模式,将其重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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