使用带有bash [duplicate]的regex重命名文件

时间:2021-07-04 10:32:48

Possible Duplicate:
rename multiple files at once in unix

可能重复:在unix中一次性重命名多个文件

I would like to rename all files from a folder using a regex (add a name to the end of name) and move to another folder.

我想使用regex对文件夹中的所有文件进行重命名(在名称末尾添加一个名称),然后移动到另一个文件夹。

It my opinion, it should be looking like this:

在我看来,应该是这样的:

mv -v ./images/*.png ./test/*test.png

but it does not work.

但它不起作用。

Can anyone suggest me a solution?

谁能给我一个解决办法吗?

4 个解决方案

#1


47  

Try this:

试试这个:

for x in *.png;do mv $x test/${x%.png}test.png;done

#2


51  

If you are on a linux, check special rename command which would do just that - renaming using regular expressions.

如果您使用的是linux,请检查特殊的rename命令,它将执行此操作——使用正则表达式重命名。

rename 's/^images\/(.+)/test\/$1.png/s' images/*.png

Otherwise, write a bash cycle over the filenames as catwalk suggested.

否则,按照猫步的建议,在文件名上写一个bash循环。

#3


37  

$ for old in ./images*.png; do
    new=$(echo $old | sed -e 's/\.png$/test.png/')
    mv -v "$old" "$new"
  done

#4


5  

Yet another solution would be a tool called "mmv": mmv "./images/*.png" "./test/#1test.png"

另一个解决方案是一个叫做“mmv”的工具:mmv。/images/*。png。/测试/ # 1 test.png”

#1


47  

Try this:

试试这个:

for x in *.png;do mv $x test/${x%.png}test.png;done

#2


51  

If you are on a linux, check special rename command which would do just that - renaming using regular expressions.

如果您使用的是linux,请检查特殊的rename命令,它将执行此操作——使用正则表达式重命名。

rename 's/^images\/(.+)/test\/$1.png/s' images/*.png

Otherwise, write a bash cycle over the filenames as catwalk suggested.

否则,按照猫步的建议,在文件名上写一个bash循环。

#3


37  

$ for old in ./images*.png; do
    new=$(echo $old | sed -e 's/\.png$/test.png/')
    mv -v "$old" "$new"
  done

#4


5  

Yet another solution would be a tool called "mmv": mmv "./images/*.png" "./test/#1test.png"

另一个解决方案是一个叫做“mmv”的工具:mmv。/images/*。png。/测试/ # 1 test.png”