You can use the shell's parameter expansion feature: in particular
${parameter#word}
${parameter##word}
Remove matching prefix pattern. The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
the beginning of the value of parameter, then the result of the
expansion is the expanded value of parameter with the shortest
matching pattern (the ``#'' case) or the longest matching pat‐
tern (the ``##'' case) deleted.
So something like
for file in *; do echo mv -- "$file" "${file##*=}"; done
(remove the echo
if it appears to do the right thing).
One issue you may face is that filenames may become non-unique once the prefixes are removed. You can either choose to skip renaming these cases using the -n
or --no-clobber
option to mv
:
for file in *; do mv --no-clobber -- "$file" "${file##*=}"; done
or use the -b
or --backup
option to create distinct backups: most straightforwardly
for file in *; do mv --backup=numbered -- "$file" "${file##*=}"; done
which will add distinguishing suffixes .~1~
, .~2~
and so on.
${var##pattern}
parameter expansion construct?