You could do this with a simple for
-loop and some shell magic:
for file in idex.*; do
mv "$file" "index${file#idex}"
done
Yes, you could also put this into one line. ;)
${var#pattern}
evaluates to $var
with a leading pattern
removed (where pattern
is a glob(7)
pattern). There exist four variants of this (POSIX compliant):
${var#pattern}
evaluates to $var
with a leading pattern
removed (non-greedy).
${var##pattern}
evaluates to $var
with a leading pattern
removed (greedy).
${var%pattern}
evaluates to $var
with a trailing pattern
removed (non-greedy).
${var%%pattern}
evaluates to $var
with a trailing pattern
removed (greedy).
Difference to non-greedy and greedy is that if you have for example $var
set to foo.bar.baz
, ${var%.*}
will evaluate to foo.bar
, but ${var%%.*}
will evaluate to foo
. This is because ${var%.*}
will search for the shortest pattern matching .*
(thus from last .
to end), where ${var%%.*}
will search for the longest one (thus from first .
to end).
You can help yourself memorizing which version are the non-greedy and the greedy ones simply with memorizing that the longer (#
resp. %
twice) search for a longer match.