Linux 中更改多个文件的名称
我在 ubuntu 机器上有许多名为 a1.txt、b1.txt、c1、txt...的文件。
有没有快速的方法将所有文件名更改为a2.txt、b2.txt、c2.txt...?
特别是,我想替换部分名称字符串。例如,每个文件名都包含一个名为“apple”的字符串,我想将所有文件名中的“apple”替换为“pear”。
有什么命令或脚本吗?
I have a number of files with names a1.txt, b1.txt, c1,txt...on ubuntu machine.
Is there any quick way to change all file names to a2.txt, b2.txt, c2.txt...?
In particular, I'd like to replace part of the name string. For instance, every file name contains a string called "apple" and I want to replace "apple" with "pear" in all file names.
Any command or script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
无需任何额外的软件,您就可以:
without any extra software you can:
如果输出看起来正确,请将“echo”替换为“mv”。
第一行中的大括号至少应该适用于 bash。
replace 'echo' with 'mv' if the output looks correct.
The curly brackets in line 1 should work with bash at least.
以下命令将通过用
2
替换名称中第一次出现的1
来重命名指定文件:The following command will rename the specified files by replacing the first occurrence of
1
in their name by2
:这是另一个对我有用的选项(按照上面的示例),适用于不同子目录中的文件
Here's another option that worked for me (following the examples above) for files in different subdirectories
像这样的事情应该有效:
修改以满足您的需求。
Something like this should work:
Modify to suit your needs.