Unix Shell - Solution: Rename file names to lower case, but not dirs

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2006 > Solution: Rename file names to lower case, but not dirs





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Solution: Rename file names to lower case, but not dirs
* Tong *

2006-11-28, 7:24 pm

On Tue, 28 Nov 2006 07:16:07 +0000, Stephane CHAZELAS wrote:

> find . -type f -name '*[[:upper:]]' -print0 -exec rename -v '
> s,(.*/)(.*),$1\L$2,' {} +


Thanks, that works, although didn't work at my first trial -- maybe
because missing the ending '*' after [[:upper:]].

Anyway, this is what I used:

find . -type f -exec rename -v 's/[_ ]//g; s,(.*/)(.*),$1\L$2,' {} \;

BTW, Just for the information, both Bill and Adam's suggestion won't work
because rename will try to lower case the dir names as well.

--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/


--
Posted via a free Usenet account from http://www.teranews.com

Stephane CHAZELAS

2006-11-28, 7:24 pm

2006-11-28, 15:52(-05), * Tong *:
> On Tue, 28 Nov 2006 07:16:07 +0000, Stephane CHAZELAS wrote:
>
>
> Thanks, that works, although didn't work at my first trial -- maybe
> because missing the ending '*' after [[:upper:]].
>
> Anyway, this is what I used:
>
> find . -type f -exec rename -v 's/[_ ]//g; s,(.*/)(.*),$1\L$2,' {} \;
>
> BTW, Just for the information, both Bill and Adam's suggestion won't work
> because rename will try to lower case the dir names as well.

[...]

And in your solution above it won't work if the dirs have spaces
or underscores in their name for the same reason. You could do:

find . -type f -exec rename -v '
s,[^/]*$,$_=lc$&;s/[_ ]//g;$_,e' {} +

Note the "+" instead of ";" to avoid having to call rename for
every file. It should work with any POSIX or Unix conformant find.

--
Stéphane
* Tong *

2006-11-28, 7:24 pm

On Tue, 28 Nov 2006 21:06:45 +0000, Stephane CHAZELAS wrote:

> And in your solution above it won't work if the dirs have spaces
> or underscores in their name for the same reason. You could do:


I used 'find . -type d' to tidy up my dir names first. thanks for the
complete solution. I know how to avoid this step now.

> Note the "+" instead of ";" to avoid having to call rename for
> every file. It should work with any POSIX or Unix conferment find.


thx, learned another trick here as well. Now I don't need to do

find . -print0 | xargs -t0 ...

to avoid exec invocation on every file any more...

--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/


--
Posted via a free Usenet account from http://www.teranews.com

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com