2

I have more than hundred directories named SP_[number]_date. I'd like to rename all to just SP_[number].

I can only figure out how to do that by mv SP_1_date SP_1 but that will take ages. Can I rename all at once? I thought that I could do something like for num in ./*; do mv SP_$num_date SP_$num; done but it doesn't do the trick.

Ditte
  • 329

1 Answers1

6

A simple enough bash way:

for i in *_date
do
    mv "$i" "${i%%_date}"
done

${i%%_date} removes a trailing _date from the string in i.

muru
  • 207,228