Tuesday, April 21, 2015

Unix Bash rename files using a regex


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.


It my opinion, it should be looking like this:


mv -v ./images/*.png ./test/*test.png, but it is not working.


Can anyone suggest me a solution?


Answer



I also like the rename command that John T posted, but it's not available on all systems. This should work everywhere:


for i in *.png; do mv -v $i `basename $i .png`.test.png; done

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...