On Sat, Sep 25, 2010 at 8:49 AM, Marc Groenewegen
wrote:
The if [ $oldname != $newname ] bit is nice; avoids errors with mv.
You could also get rid of other nasties with
newname=`echo $f | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed
's/_-_/_/g'`
But if directories have spaces as well, one solution is (from somewhere
on the Arch Linux forums)
#! /bin/bash
# remove spaces from directory names and contents recursively
IFS=$'\n'
function cleanup {
if [ -d "$1" ];
then
DIR="$1"
cd "$DIR"
fi
pwd
for f in `find . -maxdepth 1`; do
[ -d "$f" -a "$f" != "." ] && (cleanup "$f")
file=$(echo $f | tr ' ' '_' )
[ -e "$f" ] && [ ! -e "$file" ] && mv "$f" "$file"
done
[ "$DIR" ] && cd - > /dev/null
}
cleanup .
unset IFS
Even better is this (from perlmonks.org/?node_id=27739)
find2perl . -depth -eval 'my $o=$_; tr/_/ /; -e or rename $o,$_ or warn
"cannot rename $o to $_: $!"' | perl
Does the lot in one hit.
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user
LINUX® is a registered trademark of Linus Torvalds in the USA and other countries.
Linuxaudio.org logo copyright Thorsten Wilms © 2006.
Hosting provided by the Virginia Tech Department of Music and DISIS.