On Tue, Mar 11, 2008 at 9:21 PM, Tyrion <[EMAIL PROTECTED]> wrote:
> Andrew Lentvorski wrote:
> > Tyrion wrote:
> >> I use the following in a script to remove spaces from filenames:
> >>
> >> for i in *; do mv "$i" `echo $i | tr " " "_"`; done
> >>
> >> This of course only works in the current directory, how would I make it
> >> do all files in subdirectories as well?
> >
> > Try "find" with -exec
>
> Tried all sorts of variations of find with -exec and couldn't get
> anything to work, can someone give me an example?
>
> Here's the one I thought would work, but tr doesn't seem to work this way
>
> find -type f -exec mv '{}' `echo '{}' | tr " " "_"` \;
I found a script somewhere and modified it a bit; this should take
care of what you want:
-----SCRIPT=remove_spaces.sh-----
#!/bin/sh
read -p "The following files will have their names changed (press
enter for list):"
find . -name *\ *
read -p "If all of these files are OK to rename, hit enter. Otherwise,
hit ctrl-c to quit.
.."
find . -type f -print | grep " " | grep -v "\\$" > tmp.sh
sed "s/'//g" tmp.sh | sed "s/ /_/g" | sed "s/^\.\///" | sed "s/\&/_/g" > tmp1.sh
paste tmp.sh tmp1.sh | sed "s/^/mv \"/" | sed "s/ /\" /" > tmp2.sh
sh ./tmp2.sh
\rm tmp1.sh tmp2.sh tmp.sh
-----/SCRIPT-----
--
Brad Beyenhof http://augmentedfourth.com
I do not feel obliged to believe that the same God who has endowed us with
sense, reason, and intellect has intended us to forgo their use.
~ Galileo Galilei, astronomer and physicist (1564-1642)
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list