重命名多个文件,但仅重命名Bash中文件名的一部分 [英] Rename multiple files, but only rename part of the filename in Bash
本文介绍了重命名多个文件,但仅重命名Bash中文件名的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何重命名文件等,但是我遇到了麻烦.
I know how I can rename files and such, but I'm having trouble with this.
我只需要在for循环中重命名test-this
.
I only need to rename test-this
in a for loop.
test-this.ext
test-this.volume001+02.ext
test-this.volume002+04.ext
test-this.volume003+08.ext
test-this.volume004+16.ext
test-this.volume005+32.ext
test-this.volume006+64.ext
test-this.volume007+78.ext
推荐答案
如果所有这些文件都放在一个文件夹中并且在Linux上,则可以使用:
If you have all of these files in one folder and you're on Linux you can use:
rename 's/test-this/REPLACESTRING/g' *
结果将是:
REPLACESTRING.ext
REPLACESTRING.volume001+02.ext
REPLACESTRING.volume002+04.ext
...
rename
可以将命令作为第一个参数.这里的命令包括四个部分:
rename
can take a command as the first argument. The command here consists of four parts:
-
s
:用于将一个字符串替换为另一个字符串的标志, -
test-this
:您要替换的字符串, -
REPLACESTRING
:您要替换为搜索字符串的字符串,并且 -
g
:一个标志,指示将替换搜索字符串的所有匹配项,即,如果文件名是test-this-abc-test-this.ext
,则结果将是REPLACESTRING-abc-REPLACESTRING.ext
.
s
: flag to substitute a string with another string,test-this
: the string you want to replace,REPLACESTRING
: the string you want to replace the search string with, andg
: a flag indicating that all matches of the search string shall be replaced, i.e. if the filename istest-this-abc-test-this.ext
the result will beREPLACESTRING-abc-REPLACESTRING.ext
.
有关标志的详细说明,请参见man sed
.
Refer to man sed
for a detailed description of the flags.
这篇关于重命名多个文件,但仅重命名Bash中文件名的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文