how to batch rename the filename?

A 5 star hangout for overworked and underpaid system admins.
Post Reply
zjhxmjl
Posts: 52
Joined: 2012/04/11 11:35:08
Location: china
Contact:

how to batch rename the filename?

Post by zjhxmjl » 2012/05/18 03:19:57

How to batch rename the file name suffix with 'png'? the file name eg:A001.attach,A002.attach~A030.attach

User avatar
AlanBartlett
Forum Moderator
Posts: 9323
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

how to batch rename the filename?

Post by AlanBartlett » 2012/05/18 04:07:22

[code]
[b]for A in *.attach; do B=$(echo $A | sed 's/attach$/png/'); mv $A $B; done[/b]
[/code]
That will replace the "attach" suffix of every file with a "png" suffix.

If you would like to append a dot "png" suffix to every file, a simpler "for do done" construction can be used --

[code]
[b]for C in *.attach; do mv $C $C.png; done[/b]
[/code]

User avatar
TrevorH
Forum Moderator
Posts: 26596
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: how to batch rename the filename?

Post by TrevorH » 2012/05/18 15:45:30

Or..

[code]
$ rpm -qf `which rename`
util-linux-2.13-0.59.el5.x86_64
$ rename .attach .png *.attach
[/code]

zjhxmjl
Posts: 52
Joined: 2012/04/11 11:35:08
Location: china
Contact:

Re: how to batch rename the filename?

Post by zjhxmjl » 2012/05/18 23:55:33

Thank you very much!

shanemario
Posts: 2
Joined: 2016/05/11 19:26:21

Re: how to batch rename the filename?

Post by shanemario » 2016/05/11 19:29:32

How would i batch rename and change the number sequennce of a tiff sequence... ie

ThePicture_UHD_24p_98789976.tiff
ThePicture_UHD_24p_98789977.tiff
...

change that to
ThePicture_UHD_24p_98700000.tiff
ThePicture_UHD_24p_98700001.tiff
...

thanks!!

Post Reply

Return to “CentOS Social”