#!/bin/bash # rinomina.sh # script per rinominare, ad esempio, tutte le foto scaricate dalla digitale # Io sono un commento # dopo aver salvato il batch eseguire chgmod +x per renderlo eseguibile # non cambiate la prima linea, deve restare cosi' com'e' # ArenaHome 14Maggio2007 clear echo "Ti ricordo che il path e' " $PATH echo "Oggi e' `date`" # usa l'output del comando 'date' echo "Buongiorno " $LOGNAME echo "Questa macchina e': `uname -a`" # usa l'output del comando echo "Il mio nome e' $0" # variabile interna if [ -z "$1" ] then echo "---------HELP----------"; echo "SINTAX: $0 | -h (for help)"; PREFIX="FOTO_" else if [ "$1" = "-h" ] then echo "---------HELP----------"; echo "SINTAX: $0 | -h (for help)"; echo "SINTAX: $0 "; echo "OTTIENI: A partire dalla dir da dove lanci lo script, tutte le immagini con estensione"; echo "jpg, gif, tiff, rinominate con un default FOTO_xxxx.yyy"; echo "ESEMPIO: $0 "; echo "RISULTATO: FOTO_O0001.jpg"; echo "SINTAX: $0 "; echo "OTTIENI: A partire dalla dir da dove lanci lo script, tutte le immagini con estensione"; echo "jpg, gif, tiff, rinominate con il prefisso che hai digitato"; echo "ESEMPIO: $0 Pluto_Novembre_"; echo "RISULTATO: Pluto_Novembre_O0001.jpg"; exit 0 fi PREFIX="$1" fi COUNT=1 MAXSTR=`find . -name "$PREFIX*" -type f|awk -F"/" '{print $NF}'|cut -d"." -f1|sed s/$PREFIX//|sort -un|tail -1` MAX=`echo $MAXSTR|awk '{print $1+1}'` if [ "$MAX" -gt "$COUNT" ] then COUNT=$MAX fi for FILE in `find . -name "*" ! -name "$PREFIX*" -type f|awk -F"/" '{print $NF}'|sed s/' '/#/g` do NOME=`echo $FILE|cut -d"." -f1` EXT=`echo $FILE|cut -d"." -f2` ext=`echo $EXT|tr [:upper:] [:lower:]` if [ "$ext" = "jpg" -o "$ext" = "gif" -o "$ext" = "tiff" ] then LEN=`echo $COUNT|awk '{for (i=length($1);i<4;i++) c="0"c} END {print c}'` COUNTSTR="$LEN$COUNT" TARGET_NAME="$PREFIX$COUNTSTR.$ext" FILE_ORIG=`echo $FILE|sed s/#/' '/g` mv -i "$FILE_ORIG" $TARGET_NAME let COUNT=$COUNT+1 fi done