Rename files using a regex with bash
RegexBashRegex Problem Overview
> 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?
Regex Solutions
Solution 1 - Regex
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.
Solution 2 - Regex
Try this:
for x in *.png;do mv $x test/${x%.png}test.png;done
Solution 3 - Regex
$ for old in ./images*.png; do
new=$(echo $old | sed -e 's/\.png$/test.png/')
mv -v "$old" "$new"
done
Solution 4 - Regex
Yet another solution would be a tool called "mmv": mmv "./images/*.png" "./test/#1test.png"