Rename files using a regex with bash


Question

Possible Duplicate:
rename multiple files at once in 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.

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?

1
48
6/24/2018 2:47:33 PM

Accepted Answer

Try this:

for x in *.png;do mv $x test/${x%.png}test.png;done
53
12/25/2009 2:50:01 PM

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

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

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


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon