#!/bin/bash # ESEMPI: #toglie una parte del nome (a-l.) e la sostituisce con nulla #for i in `ls *ogm`; do mv $i ${i/"a-l."/}; done # #cambia tutti i '_' in ' ' #for i in `ls *.avi`; do mv "$i" "${i//_/ }"; done # # THE SCRIPT: echo "`basename $0` (c)2007-2010 PaulTT" if [ $# -lt 4 ]; then set "" fi case $1 in -a|-s);; *) echo "Usage: " echo " `basename $0` <-a|-s> '[*][*]' 'from' 'to'" echo " substitutes 'from' with 'to' in \"'filename'\"" echo " and yes, you have to specify the \"'\" around from and to patterns" echo " a pattern for matching filenames can be used, for example '*.avi'" echo " (this one with apices too!!)" echo " -a means all occurences in filename, -s only the first one" echo "" exit 1 ;; esac IFS=$'\n\t' PTT_MODE="$1" PTT_FILES="$2" PTT_FROM="$3" PTT_TO="$4" echo "I will do: " for i in `ls -1 $PTT_FILES`; do if [ "$PTT_MODE" == "-a" ]; then if [ "$i" != "${i//$PTT_FROM/$PTT_TO}" ]; then echo " mv \"$i\" \"${i//$PTT_FROM/$PTT_TO}\"" else echo " \"$i\" not modified" fi else if [ "$i" != "${i/$PTT_FROM/$PTT_TO}" ]; then echo " mv \"$i\" \"${i/$PTT_FROM/$PTT_TO}\"" else echo " \"$i\" not modified" fi fi done echo -n "Are You Sure? [y/N] " read reply case $reply in n* | N*) echo "doing nothing, bye bye" exit ;; y* | Y*) for i in `ls -1 $PTT_FILES`; do if [ "$PTT_MODE" == "-a" ]; then if [ "$i" != "${i//$PTT_FROM/$PTT_TO}" ]; then mv "$i" "${i//$PTT_FROM/$PTT_TO}" fi else if [ "$i" != "${i/$PTT_FROM/$PTT_TO}" ]; then mv "$i" "${i/$PTT_FROM/$PTT_TO}" fi fi done ;; *) echo "doing nothing, bye bye" exit ;; esac