Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename files using a regex with bash [duplicate]

Tags:

regex

bash

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?

like image 838
mxg Avatar asked Dec 25 '09 14:12

mxg


People also ask

How do I rename a file in bash?

To rename a file in bash we use mv command: -v : Verbose option. In other words, display the progress of the files as they are being moved or renamed in a bash shell.

How do I copy and rename multiple files in Linux?

If you want to rename multiple files when you copy them, the easiest way is to write a script to do it. Then edit mycp.sh with your preferred text editor and change newfile on each cp command line to whatever you want to rename that copied file to.


1 Answers

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.

like image 168
kibitzer Avatar answered Sep 23 '22 19:09

kibitzer