Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename multiple files in bash

Tags:

linux

bash

shell

I have A.js, B.js, C.js in a certain directory and I want to write a SINGLE command line in bash shell to rename these files _A, _B, _C. How can I do this?

I tried find -name '*.sh' | xargs -I file mv file basename file .sh but it doesn't work, basename file .sh isn't recognized as a nested command

like image 576
andPat Avatar asked Dec 16 '22 13:12

andPat


1 Answers

How about

rename 's/(.*).js/_$1/' *.js

Check the syntax for rename on your system.

The above command will rename A.js to _A & so on.

If you want to retain the extension, below should help:

rename 's/(.*)/_$1/' *.js
like image 67
anishsane Avatar answered Dec 29 '22 22:12

anishsane