[Samba] file names convert

Michael Wood esiotrot at gmail.com
Fri Sep 17 02:24:29 MDT 2010


On 16 September 2010 16:51, Lennart Sorensen
<lsorense at csclub.uwaterloo.ca> wrote:
> On Thu, Sep 16, 2010 at 01:38:05PM +0200, Michael Wood wrote:
>> On 16 September 2010 09:02, Alessio Tomelleri - ARPAV Dipartimento di
>> Belluno <atomelleri at arpa.veneto.it> wrote:
>> >  ..maybe could be useful this command ?!  get a closer look   "man tr"
>> >
>> > tr [:upper:] [:lower:] < myfile
>>
>> He wants to change the filename, not the contents :)
>>
>> > maybe, inserting it in a script as well...
>>
>> Try something like:
>>
>> for f in *; do
>
> Breaks on filenames with spaces.

No, it does not:

$ touch "File With Spaces.txt"
$ touch "Other File Also With Spaces.txt"
$ touch lowercase.txt
$ touch duplicate.txt
$ touch DUPLICATE.txt
$ for f in *; do lower="`echo $f | tr [:upper:] [:lower:]`"; if [ "$f"
!= "$lower" ]; then mv -i "$f" "$lower"; fi; done
mv: overwrite `duplicate.txt'? n
$ ls -l
total 0
-rw-r--r-- 1 michael michael 0 2010-09-17 10:19 duplicate.txt
-rw-r--r-- 1 michael michael 0 2010-09-17 10:19 DUPLICATE.txt
-rw-r--r-- 1 michael michael 0 2010-09-17 10:18 file with spaces.txt
-rw-r--r-- 1 michael michael 0 2010-09-17 10:19 lowercase.txt
-rw-r--r-- 1 michael michael 0 2010-09-17 10:19 other file also with spaces.txt

>>     lower="`echo $f | tr [:upper:] [:lower:]`"
>>     if [ "$f" != "$lower" ]; then
>>         mv -i "$f" "$lower"
>>     fi
>> done
>>
>> The "mv -i" is in case you have a file called "README.txt" and another
>> one called "Readme.txt" in the same directory.
>>
>> Please try it out on some test files before running it in production.
>
> How about "rename 's/(.*)/\L$1\E/' filenames" ?

Ah, I wasn't aware of that.  Thanks.

-- 
Michael Wood <esiotrot at gmail.com>


More information about the samba mailing list