LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   spaces in filenames (http://www.linuxquestions.org/questions/linux-general-1/spaces-in-filenames-8609/)

ebone 11-12-2001 02:27 AM

spaces in filenames
 
what can i do to get rid of (or replace with an underscore) the spaces in filesnames copied from from my windows box to a linux box

TIA

E

unSpawn 11-12-2001 12:51 PM

Code:

#!/bin/sh
cdir=pwd
if [ ! -d "$1" ]; then
echo $1 must be dir
exit 1
else cd "$1"
for f in $(/bin/ls * | grep " "); do
nwName=$(echo "$f" | sed -e "s/ /_/g")
mv "$f" "$nwName"
done
cd $cdir
fi

Im running Bash on Linux and Windows, so this should work crossplatform, just check before deploying it, and use quotes or backslashes when entering wintendo dirnames with spaces.
It's a kinda crude solution, but it works for me.

Save this as something like "spc2uscore.sh" and invoke with the path+dirname as the single argument, changes every filename with spaces in that dir to filenames with underscores.

HTH somehow.

ebone 11-12-2001 12:56 PM

thanks, i'll give it a try

E


All times are GMT -5. The time now is 11:25 PM.