2009/7/28 Ben Stringer <[email protected]>:
>> 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
>>
>> cheers,
>> Meryl
>>
>
> Hi Meryl,
>
> Change "for f in *; do" to be "find . -type f ; do"
>
> This will recursively find all files from the current directory down.
>

If you're going to do that then you will probably want to also use
'basename' and 'dirname'.

############
#!/bin/bash

find . -type f -exec sh -c '
file=$(basename "{}" | tr A-Z a-z | tr " " _)
[ ! -f "$file" ] && echo OLD:"{}" NEW:"$(dirname "{}")/$file"
' \;
############

Edit to 'mv' when you're sure that it works...

cheers,
Owen.
--
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