#!/bin/bash set -e if [ $# -lt 2 ]; then echo "$0 [-y|a] root initcounter" exit fi move=no append=no keep=no author=no if [ "$1" = "-a" ]; then shift append=yes fi if [ "$1" = "-k" ]; then shift keep=yes fi if [ "$1" = "-e" ]; then shift author=yes fi if [ "$1" = "-y" ]; then shift move=yes fi if [ $keep != yes ]; then root=$1 shift fi j=$1 shift > /tmp/reverserename for i in "$@" do test -f "$i" || continue ext=${i##*.} if [ $keep = yes ]; then new=0${j}_${i/#[0-9]*_/} elif [ $append = yes ]; then new="${root}_${j}.$ext" elif [ $author = yes ]; then au=${i##*-} [ ! -z $au ] && au="-$au" new="${j}_${root}${au}" 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