[lug] find command or similar

Tkil tkil at scrye.com
Tue May 13 12:22:20 MDT 2003


>>>>> "Hugh" == Hugh Brown <hugh at math.byu.edu> writes:

Hugh> if you use print, then you get the whole path starting from ./
Hugh> and egrep will count the number of the chars in the path instead
Hugh> of just the filename.

Yeah, I should have read the rest of the thread before posting.

Hugh> also out of curiosity, why use -name '*' instead of -type f

Heh, didn't even see that.  Although you probably want to check for
directories that are overly-long, as well.

I thought of using "locate" as well, as it really should be a lot
faster than find -- it might not cover all the directories quite
correctly, though; I never did investigate its security and privacy
issues very thoroughly.

I'd consider using perl as the "print if it's longer than x" method,
too:

   find . -print | \
     perl -nle 'print if (len($_) - rindex($_, "/")) >= 200'

The extension to both limits is straightforward:

   find . -print | \
     perl -nle '$l = len($_) - rindex($_, "/");
                print if $l > 200 && $l < 240'

(With appropriate attention paid to off-by-one and inclusion /
exclusion issues.)

Finally, there's a nice idiom available in awk (!) for grabbing the
last field on a line.  Using "/" as the field separator:

   awk -F/ '{ print $NF }'

(perl can do something similar with the -a option.)

t.





More information about the LUG mailing list