[mdlug] How to find file name length?

Raymond McLaughlin driveray at ameritech.net
Wed Sep 26 18:51:55 EDT 2007


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?

Also did any one notice that the "echo "$(basename "{}" | wc -c" part
doesn't work as intended? Observe:

    echo filename.txt | wc -c
    13

wc counts the trailing new line as a character, you need to use "echo -n"

    echo -n filename.txt | wc -c
    12


Ray
> Michael
> _______________________________________________
> mdlug mailing list
> mdlug at mdlug.org
> http://mdlug.org/mailman/listinfo/mdlug
> 




More information about the mdlug mailing list