I use the command rename to rename multiple files at the same time as follow

but how i can make more than one change in the same command

i.e. change 1 to A and change 2 to B

* UPDATE 1 *

i used the following case to test but there was errors

touch {1..100}
rename 's/0/A/; s/1/B/; s/2/C/; s/3/D/; s/4/E/; s/5/F/; s/6/G/; s/7/H/;s/8/I/; s/9/J/' *

the result is

B    BE  C   CF  D3  DG  EA  EH  FB  FI  GC  GJ  HD  I   IE  J9  JF
B1   BF  C2  CG  DA  DH  EB  EI  FC  FJ  GD  H   HE  I8  IF  JA  JG
BA   BG  CA  CH  DB  DI  EC  EJ  FD  G   GE  H7  HF  IA  IG  JB  JH
BA0  BH  CB  CI  DC  DJ  ED  F   FE  G6  GF  HA  HG  IB  IH  JC  JI
BC   BI  CD  CJ  DE  E   EF  F5  FG  GA  GH  HB  HI  IC  IJ  JD
BD   BJ  CE  D   DF  E4  EG  FA  FH  GB  GI  HC  HJ  ID  J   JE

* Update 2 *

to solve the issue , i must use the /g . i.e 11 should be BB but to do that /g is required otherwise only the first number will be changed

so the correct command is

rename 's/0/A/g; s/1/B/g; s/2/C/g; s/3/D/g; s/4/E/g; s/5/F/g; s/6/G/g; s/7/H/g; s/8/I/g ; s/9/J/g ' *

You can insert multiple conversion patterns separated by ;:

rename 's/1/A/; s/2/B/' *

If you want to change all occurrences of 1 and 2 rather than only the first ones, use the g (global) modifier:

rename 's/1/A/g; s/2/B/g' *


$ ls -1

$ rename -n 's/1/A/; s/2/B/' *
1234 renamed as AB34
4321 renamed as 43BA
foo12bar renamed as fooABbar
spam23egg renamed as spamB3egg

$ rename 's/1/A/; s/2/B/' *

$ ls -1
| improve this answer | |

This is also possible by using one rename command:

rename 'y/A-B/1-2/' *

Example : the -n switch means "No action: print names of files to be renamed, but don't rename."

$ rename -n 'y/A-B/1-2/' *
rename(A, 1)
rename(B, 2)



Transliterates all occurrences of the characters found in the search list
with the corresponding character in the replacement list. It returns the
number of characters replaced or deleted.


| improve this answer | |
  • @A.B. thanks for the idea , it will help in case the change is sequential letters , but this is just an example – Fat Mind Nov 11 '15 at 8:40
  • @kos what do you with translation ? – Fat Mind Nov 11 '15 at 8:47
  • 2
    @FatMind It's just the name of the y/// command: perldoc.perl.org/functions/y.html – kos Nov 11 '15 at 8:55
  • 1
    @kos, Thx for the link, added =) – A.B. Nov 11 '15 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.