替换文件夹名称中的文本
如何替换 Linux 中文件夹名称中的相同文本?
假设我有“Photos_Jun”、“Photos_July”、“Photos_Aug”等,我可以将它们重命名为“Photos Jun”、“Photos July”等的最简单方法是什么(基本上我想用空格替换下划线“”我有大约 200 个这样的文件夹,
我正在寻找解决方案:如何使用 Perl 轻松批量重命名文件?
它看起来像我正在寻找的东西,但是,我不知道如何制作正则表达式来匹配字母数字后跟“_”的文件夹
。 -数字名称,所以我认为 [a-zA-Z] 是正确的开始方式,
perl -e 'foreach $f (glob("File\\ Name*")) { $nf = $f; $nf =~ s/(\d+)$/sprintf("%03d",$1)/e; print `mv \"$f\" \"$nf\"`;}'
感谢您的帮助!
How can I replace the same text in folder names in linux?
Say I have "Photos_Jun", "Photos_July", "Photos_Aug", etc. whats the simplest way I can rename them like "Photos Jun", "Photos July", etc (basically I want to replace the underscore with a space " ". I have about 200 of these folders.
I was looking at solution: How can I easily bulk rename files with Perl?
It looks like what im looking for however, I dont know how to make a regular expression to match folders that are alphanumeric followed by a "_".
All files have non-numeric names, so I think [a-zA-Z] is the right way to start.
perl -e 'foreach $f (glob("File\\ Name*")) { $nf = $f; $nf =~ s/(\d+)$/sprintf("%03d",$1)/e; print `mv \"$f\" \"$nf\"`;}'
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Linux 有一个
rename
命令:Linux has a
rename
command:如果您使用 *nix 并且不介意非 Perl 解决方案,这里有一个 shell (bash) 解决方案。满意后删除
echo
。if you are on *nix and you don't mind a non Perl solution, here's a shell (bash) solution. remove the
echo
when satisfied.展开单行:
Tu unroll the one-liner: