Meryl <[email protected]> writes:

> I have a n000b question.  I found a neat housework script to change case &
> space but I'm wondering is it possible to run it recursively?  If so where
> do I put the -r in it?
>
> #!/bin/bash
> for f in *; do 
>       file=$(echo $f | tr A-Z a-z | tr ' ' _) 
>       [ ! -f $file ] && mv "$f" $file 
> done

Personally, I would consider using rename(1) that came with Perl for this, but
you could write a shell script to do the same thing...

    find . -type f -print0 | xargs -0 rename \
        'my @name = split qr{/}; 
         $name[-1] =~ y/A-Z /a-z_/;
         $_ = join("/", @name);'

rename uses an arbitrary Perl expression to mangle $_, which is the input
filename, and the output value is the name to rename it to.

Alternately, in shell, you can do the same, but harder:

    find . -type f | while read file; do
        dir=$(dirname "$file")
        name=$(basename "$file" | tr 'A-Z ' 'a-z_')
        test x"$file" = x"$dir/$name" || mv "$file" "$dir/$name"
    done

Regards,
        Daniel
-- 
✣ Daniel Pittman            ✉ [email protected]            ☎ +61 401 155 707
               ♽ made with 100 percent post-consumer electrons
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to