#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # Rename one or multiple files, with regular expressions. # Example: # # ren foo bar # renames xxxfooyyy to xxxbaryyy # if [ $# -lt 2 ]; then cat <<-EOT >&2 Usage: `basename $0` [] is any number of filenames (default: *). is the old substring which is substituted by . sed(1) regular expressions are allowed. EOT exit 1 fi RENOLD="$1" RENNEW="$2" shift 2 if [ $# -lt 1 ]; then set -- * fi for FILEOLD in "$@"; do FILENEW=`echo "x$FILEOLD" | sed 's/^x//;s/'"$RENOLD"'/'"$RENNEW"'/g'` if [ "x$FILEOLD" != "x$FILENEW" ]; then mv -- "$FILEOLD" "$FILENEW" fi done #--