#!/bin/ksh ################################################## # Rename files in current directory that have # spaces to underscores # # To do subdirs, do a "find . -name > /tmp/myfile" # then run this script with an argument of /tmp/file. # i.e. rename_space /tmp/myfile # ################################################## if (( $# )) then FILES=$(cat $1) else FILES=* fi for FILE in $FILES do if [[ -n "$(echo "$FILE" | grep ' ')" ]] then echo "Renaming: $FILE" #spaces become underscores #other metachars are removed mv "$FILE" $(echo "$FILE" \ | tr ' ' '_' \ | sed -e 's/[(),"]//g' \ | sed -e "s/'//g" ) else echo "OK - No Action: $FILE" fi done