[mdlug] How to find file name length?
Michael Corral
micorral at comcast.net
Wed Sep 26 04:28:39 EDT 2007
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.
You can actually use just a single find command, and nothing else, to
find all the files (not including the complete path) under / with
name lengths of 104 or higher:
find / -regextype posix-egrep -type f -regex '.*/[^/]{104,}'
This is with the GNU find in Linux, which is far more powerful than
the traditional UNIX find.
Michael
More information about the mdlug
mailing list