Hi,<br><br>You should be able to modify this:<br><a href="http://www.sharons.org.uk/taste/archives/2012/05/index.html#e2012-05-01T00_50_12.txt">http://www.sharons.org.uk/taste/archives/2012/05/index.html#e2012-05-01T00_50_12.txt</a><br>
<br><ul><li>If you want to rename directories also, then just remove the:<span style="font-family:courier new,monospace"> -type f</span></li><li>If you want to do ALL files then remove the sections relating to name: <span style="font-family:courier new,monospace">-name '*.MP3'</span></li>
<li>If you want to go based on a name filter, you can actualy keep the command more simple using case insensitive name matching: <span style="font-family:courier new,monospace">-iname "*.mp3" </span><br></li><li>
Rather than the more convoluted: <span style="font-family:courier new,monospace">\( -name '*.mp3' -o -name '*.MP3' \)</span></li></ul><p>You should end up with something like this:</p><p>#!/bin/bash<br></p>
<p>find $1 -name "* *" |<br>
while IFS= read -r NAME;<br>
do<br> DEST=`echo "$NAME" | tr ' ' '_'`<br> mv -v "${NAME}" "${DEST}"<br>
done</p>Tested by adding that to a script: <span style="font-family:courier new,monospace">test.sh</span><br><br>Sample usage:<br><span style="font-family:courier new,monospace">[user@host]$ mkdir test</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">[user@host]$ touch test/"file one.txt"</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">[user@host]$ touch test/"file two.txt"</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">[user@host]$ touch test/"filethree.txt"</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">[user@host]$ ls test/</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">file one.txt filethree.txt file two.txt</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">[user@host]$ ./test.sh test/</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">`test/file one.txt' -> `test/file_one.txt'</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">`test/file two.txt' -> `test/file_two.txt'</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">[user@host]$ ls test/</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">file_one.txt filethree.txt file_two.txt</span><br>
<br><br>The <span style="font-family:courier new,monospace">-name "* *"</span> searches for anything with a name containing a space (no pint in modifying files without spaces). You can change it to <span style="font-family:courier new,monospace">"* *.mp3"</span> for mp3 files only. Or use <span style="font-family:courier new,monospace">-iname</span> for case insensitive searches.<br>
<br><br><div class="gmail_quote">On 14 May 2012 23:04, sharon kimble <span dir="ltr"><<a href="mailto:boudiccas@talktalk.net" target="_blank">boudiccas@talktalk.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This is probably quite easy if you already know the answer, but I'm not very<br>
good at scripting.What I'm looking for is a script to go through my<br>
/home/foo/Music directory converting all the album titles with spaces in to<br>
convert them to underscores.<br>
<br>
Can anyone help please?<br>
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888">Sharon.<br>
--<br>
A taste of linux = <a href="http://www.sharons.org.uk/taste/index.html" target="_blank">http://www.sharons.org.uk/taste/index.html</a><br>
efever = <a href="http://www.efever.blogspot.com/" target="_blank">http://www.efever.blogspot.com/</a><br>
efever = <a href="http://sharon04.livejournal.com/" target="_blank">http://sharon04.livejournal.com/</a><br>
Debian 6,0.5, Gnome 1:2.30+7, LibreOffice 3.4.6<br>
Registered Linux user 334501<br>
<br>
_______________________________________________<br>
Kent mailing list<br>
<a href="mailto:Kent@mailman.lug.org.uk">Kent@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/kent" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/kent</a><br>
</font></span></blockquote></div><br>