David
David

Reputation: 1267

Changing name to files in bash respecting the number associated to each file

I have a bunch of files in bash named myfile1.sh, myfile2.sh, myfile3.sh... and so on. I would like to remove the sh part in each one of them, that is: rename to myfile1, myfile2, myfile3, ... Do you have a suggestion to do it all at once?

Thanks in advance.

Upvotes: 0

Views: 68

Answers (2)

P.P
P.P

Reputation: 121357

If you have the rename command, you can use it:

rename 's/\.sh$//' *.sh

A bash one-liner can be:

for f in *.sh; do mv "$f" "${f%.sh}"; done

Upvotes: 0

Hielke Walinga
Hielke Walinga

Reputation: 2845

for i in *.sh; do mv "$i" "${i%.sh}"; done

Upvotes: 2

Related Questions