#!/bin/bash echo `basename $0`, Spawn 2005 #Special thanks to PaulTT for the extension take.. :) recursive() { for file in * do if [ $OPTION -eq 1 ] ; then if [ -d "$file" ] ; then cd $file recursive . $OPTION fi fi if [ ! -d "$file" ]; then EXTEN=$(echo $file | sed -e 's/.*\.//') nuovo=${file%.*} nuovo=${nuovo//_/ } nuovo=${nuovo/-/ - } nuovo=${nuovo//./ } nuovo=${nuovo/ - / - } FIRST=${nuovo:0:1} REST=`echo ${nuovo:1} | tr A-Z a-z` if [ "$file" != "$EXTEN" ]; then if [ "$file" != "$FIRST$REST.$EXTEN" ]; then mv "$file" "$FIRST$REST.$EXTEN" file=$FIRST$REST.$EXTEN else continue fi else if [ "$file" != "$FIRST$REST" ]; then mv "$file" "$FIRST$REST" file=$FIRST$REST else continue fi fi fi done } OPTION=0 case $1 in "-h") echo " A script to rename automatically all the files which have got underscores" echo " in place of whitespaces or which have all capital characters" echo "" echo " Usage: `basename $0` [-r -h]" echo " -h show this help and exit" echo " -r rename files in recursive mode" echo " Example: ThIs.Is.My_FuCkeD-FiLe This is my fucked - file" exit 0 ;; "-r") OPTION=1 ;; "") #do nothin! ;; "*") $0 -h echo "'$1' option not recognized!" exit 1 ;; esac recursive