简体   繁体   English

Linux将now.jpg.1重命名为spy_1.html

[英]Linux renaming now.jpg.1 to spy_1.html

I want to use linux to rename 10 files. 我想使用linux重命名10个文件。

now.jpg to spy_.html now.jpg至spy_.html

And the other 9 should be 另外九个应该是

now.jpg.1 to spy_html.1 从now.jpg.1到spy_html.1

now.jpg.2 to spy_html.2 从now.jpg.2到spy_html.2

And so forth. 依此类推。

So far I have come up with this: 到目前为止,我已经提出了:

for f in *.jpg
do
mv “$f” “(“%s”%p”%i”%o”%n”%_).html”
done

But it doesn't work. 但这是行不通的。 Any tips appreciated. 任何提示表示赞赏。

You could use regular expression to capture the optional numeric extension and add it to the target file name. 您可以使用正则表达式捕获可选的数字扩展名并将其添加到目标文件名。 This should work with bash: 这应该与bash一起使用:

for f in *.jpg*
do
  if [[ $f =~ now\.jpg(\.[0-9])? ]]; then
    mv "$f" "spy.html${BASH_REMATCH[1]}"
  fi
done

assuming you want spy.html[.#] . 假设您想要spy.html[.#] If you want an underscore for the files with the numerical extension, ie spy_html.1 , it would be easier to issue two commands, one for now.jpg and one loop for the now.jpg.* . 如果要为带有数字扩展名的文件(即spy_html.1 ,则发出两个命令会更容易,一个命令用于now.jpg ,一个循环用于now.jpg.*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM