LinuxQuestions.org

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

ebone 11-12-2001 01: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 11:51 AM

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 11:56 AM

thanks, i'll give it a try

E


All times are GMT -5. The time now is 01:58 PM.