#!/bin/bash # By Marc MERLIN set -e if [ $# -lt 2 ]; then echo "$0 [-y|a] rootname initcounter" echo "typical is: $0 -y images 100 *.jpg" exit fi move=no append=no if [ "$1" = "-a" ]; then shift append=yes fi if [ "$1" = "-y" ]; then shift move=yes fi root=$1 j=$2 shift 2 > /tmp/reverserename for i in $* do test -f $i || continue ext=${i##*.} if [ $append = yes ]; then new="${root}_${j}.$ext" else new="${j}_${root}.$ext" fi echo "$i -> $new" echo "mv $new $i" >> /tmp/reverserename if [ $move = yes ]; then mv $i $new fi j=`expr $j + 1` done