使用正则表达式重命名多个文件 [英] Rename multiple files with regular expression
问题描述
我从互联网上下载了一些文件.在这些文件的名称字段中,每个' '
字符均替换为"%20"
.我想重命名所有这些文件,但是文件数太多.因此,手动方法将很笨拙.我知道从命令行使用正则表达式可以做到这一点,但我对此并不十分熟悉.几乎不需要什么帮助.
I downloaded some files from internet. In the name field of those files each ' '
character is replaced by "%20"
. I want to rename all of those but number of files is too high. So manual approach would be clumsy. I know from command line with regular expression this can be done but I am not very familiar with it. So little help is needed.
总结是,我想通过用" "
替换所有"%20"
模式来重命名目录中的所有文件.我该怎么办?
Summary is, I want to rename all files in a directory by replacing all "%20"
patterns with " "
. How can I do it?
示例:
17%20Clipping.cpp --> 17 Clipping.cpp
14%20Mouse%20(Button)%20Listener.cpp --> 14 Mouse (Button) Listener.cpp
推荐答案
您可以使用接受正则表达式的命令rename
重命名一组文件
you can rename a group of files using command rename
that accept regular expression
例如,要重命名所有匹配"* .bak"的文件以去除扩展名,您可能会说
For example, to rename all files matching "*.bak" to strip the extension, you might say
rename 's/\.bak$//' *.bak
要将大写名称转换为小写,请使用
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
和您的答案:
rename 's/%20/ /' *.cpp
这篇关于使用正则表达式重命名多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!