How to do a mass rename?

2019-01-05 03:35发布

I need to rename files names like this

transform.php?dappName=Test&transformer=YAML&v_id=XXXXX

to just this

XXXXX.txt

How can I do it?

I understand that i need more than one mv command because they are at least 25000 files.

11条回答
Rolldiameter
2楼-- · 2019-01-05 04:12

Try the rename command

Or you could pipe the results of an ls into a perl regex.

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-05 04:12
find -name '*v_id=*' | perl -lne'rename($_, qq($1.txt)) if /v_id=(\S+)/'
查看更多
Luminary・发光体
4楼-- · 2019-01-05 04:12

This should also work:

prfx='transform.php?dappName=Test&transformer=YAML&v_id='

ls $prfx* | sed s/$prfx// | xargs -Ipsx mv "$prfx"psx psx

查看更多
▲ chillily
5楼-- · 2019-01-05 04:13

this renamer command would do it:

$ renamer --regex --find 'transform.php?dappName=Test&transformer=YAML&v_id=(\w+)' --replace '$1.txt' *
查看更多
来,给爷笑一个
6楼-- · 2019-01-05 04:14

vimv lets you rename multiple files using Vim's text editing capabilities.

Entering vimv opens a Vim window which lists down all files and you can do pattern matching, visual select, etc to edit the names. After you exit Vim, the files will be renamed.

[Disclaimer: I'm the author of the tool]

查看更多
登录 后发表回答