replace space by _

Hi

I need to know how I change the spaces by _ in folders and filder founded by find

ex.

find . -name "* *" -exec echo {} \;

./test space
./test space/new file.txt
./test space/new file
./test space/untitled folder
./test space/untitled folder/new fileruben
./Backup/backup/Image for linux Key
./Backup/backup/dings/Backup tool
./Backup/backup/dings/backup reading diff.sh

which option should I exec??

thanks

Try it first without the coloured part to insure the commands are correct:

find . -name "* *" -exec echo {} \; |
sed 's/\(.*\) \(.*\)/mv & \1_\2/' | sh

Regards

Hi

thanks a lot for you script but something strange is happaning. The verbose is correct but nothing happens.
It say mv ./new file.txt ./new_file.txt (which is correct) but then it stills the same, even with sudo

and the couloured part gives error

Any idea? thanks a lot

As i dont have unix machine i havent verified the code in the machine ,
so i suggest you to test code no 1 , if it works then you can proceed with code no 2
#=========
#Code No : 1
#==========

for i in `find . -name "*" `
do
fil_path=`echo $i|tr -s |tr ' ' '_'`
echo New fil_path : $fil_path
done

#=========
#Code No : 2
#==========
for i in `find . -name "*" `
do
fil_path=`echo $i|tr -s |tr ' ' '_'`
echo fil_path : $fil_path

mv $i $fil_path

done

I hope it works ...........

hmm I know why

I have to do mv ./new\ file.txt ./new_file.txt

with the \ in the space
I think that I can first echo to a file then in the file take the spaces and then use the file to change the space by a _
Do you think it's possible?

find . -name "* *" -exec echo {} \; | sed 's/\(.*\) \(.*\)/mv "&" "\1_\2/"' | sh

this might work ...but u may need to change it accordingly

for i in `find . -name "*" `
do

fil_path=`echo $i|tr -s |tr ' ' ''`|tr '\' ''

echo fil_path : $fil_path

mv $i $fil_path

done