newbie
newbie

Reputation: 4789

rename multiple files in a directory

I have a bunch of files in a directory. The file names are created like this: a_dc.ac.txt, a_dc.aa.txt, a_dc.cc.txt and so on. I need to replace all the a_dc portion of the names to a_adj. I tried the following but it's not working:

rename 's/a_dc/a_adj/s' *

Is there any other way to fix this? I am not sure why rename is not working.

P.S. I am using centos

Upvotes: 2

Views: 266

Answers (1)

anubhava
anubhava

Reputation: 784878

Using find one-liner:

find . -maxdepth 1 -name 'a_dc.*.txt' -exec bash -c 'x="{}"; mv "$x" "a_adj.${x#*.*.}"' \;

Upvotes: 3

Related Questions