[mdlug] How to find file name length?

Michael Corral micorral at comcast.net
Wed Sep 26 20:16:11 EDT 2007


2007-09-26, Monsieur Raymond McLaughlin a ecrit:
> Michael Corral wrote:
>> 2007-09-26, Monsieur Raymond McLaughlin a ecrit:
>>> Paul wrote:
>>>> Well, this is almost perverse (and probably slow), but
>>>> this invokation will tell you all the files greater than 99
>>>> characters long (in theory):
>>>>
>>>> #>  find / -type f -exec bash -c 'echo "$(basename "{}" | wc -c) {}" ' \;
>>>> 	| egrep '^1[0-9]{2}'
>>> Actually "egrep '^1[0-9]{2}'" only filters for numbers 100-199. A more
>>> general construct: "egrep '[0-9]{3,}'" will find all numbers of three or
>>> more digits. Don't some filesystems allow for filenames of 255 or more
>>> characters?
>>
>> Well, even that would exclude filenames of length 100, 101, 102 and
>> 103, which the original poster said were valid lengths.
>
> Oh? I tested the egrep statement thus:
> pts/1 $ for ((i=1; i<216; ++i)); do echo $i; done | \
> egrep '[0-9]{3,}'
> 100
> 101
> 102
> 103
> 104
> 105
> <snip>
> 212
> 213
> 214
> 215
>
> How are 100-103 excluded?

100-103 are valid filename lengths, so your "filter" would wrongly
exclude them from the valid list. You need a way of only excluding
lengths of 104 or higher. Maybe it's poor semantics on my part, I
guess I could rephrase it as "only lengths of 104 or higher should
be *included* in the *invalid* list".

Michael



More information about the mdlug mailing list