Bash
With pure Bash, removing everything up to the first -
:
for f in *; do mv -- "$f" "${f#*- }"; done
If you want to remove everything up to the last -
, use ##
instead of #
.
To break it down:
- The
for
iterates over every file in the current directory (*
), and calls mv
on each file found.
- The
--
tells mv
to stop parsing options and is a safeguard to prevent files starting with -
from being interpreted as options (e.g. a file called -i
would cause mv
to prompt you before moving).
- The
${f#*- }
is string manipulation and removes the part you don't want from each filename.
- All variables are quoted to prevent filenames with spaces or globbing characters to break the command. Always double-quote your variables.
rename
With rename
that's commonly found in Linux distributions, e.g. if you want to specify the artist:
rename 's/Versailles - //' *
Or if you want to remove everything up to the last -
:
rename 's/.*- //' *
Zsh
In Zsh and zmv
, which you need to load with autoload -U zmv
:
zmv 'Versailles - (*)' '$1'