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.
rename
expression would bes/_date$//
– muru Aug 10 '15 at 07:20date
literal or is a date, like inSP_1_May 12, 2015
? – Rmano Aug 10 '15 at 10:50mv SP_$num_date SP_$num
didn't work was that you don't have a variable$num_date
(or, at least, that's one of the reasons). You would have needed${num}_date
to separate the variable$num
from a constant suffix_date
. Another problem is that the value in$num
might be./SP_1_date
so themv
command was attempting to moveSP_./
(since$num_date
was undefined and hence an empty string) toSP_./SP_1_date
. – Jonathan Leffler Aug 10 '15 at 14:30