Batch renaming files
On Debian and derivatives, Perl's rename
works similarly to sed
like this:
rename -v 's/image//' *.png
There's also the rename
from util-linux
that works like this, instead:
rename image '' *.png
If you are using Bash or other POSIX-compatible shell:
for f in *.png; do
mv -- "$f" "${f#image}"
done
zmv
The zsh shell has a powerful batch rename command called zmv
.
First you need to enable the zmv
command as follows (this can go into your ~/.zshrc
).
autoload zmv
The basic syntax is zmv PATTERN REPLACEMENT
. The pattern is a shell glob expression. Parts of the pattern can be surrounded by parentheses. The replacement text can contain $1
, $2
, etc. to refer to the Nth parenthesised group in the pattern. For example:
zmv 'image(*.png)' '$1'
You can also ask zsh to automatically define $1
, $2
, etc. to match the wildcard characters in the pattern:
zmv -w 'image*.png' '$1.png'