dj199008
dj199008

Reputation: 1789

Rename file in a directory using shell

Suppose I have some files in a dir called test_dir, like a.sh, b.sh, c.sh, d.bash, and so on. I need to change all the file *.sh to *.bash. How can I achieve it using shell?

Upvotes: 0

Views: 72

Answers (1)

Cyrille
Cyrille

Reputation: 25144

Can be done in a single one-liner:

ls *.sh | while read i; do mv "$i" "${i%.sh}.bash"; done

Upvotes: 2

Related Questions