How do I search for all files of a certain length in a directory, in Unix? For example, how do I search for all files whose names are of length 5 in the directory /blah?

I've looked all over and I can't find it at all.

link|improve this question
feedback

migrated from stackoverflow.com Sep 19 '11 at 20:37

This question came from our site for professional and enthusiast programmers.

3 Answers

Anything wrong with

ls /blah/?????

As in

$ ls blah/*
blah/apple  blah/bananas  blah/pears  blah/pie

$ ls blah/?????
blah/apple  blah/pears
link|improve this answer
+1 from me for simplicity. – zpletan Sep 20 '11 at 2:07
+1 ? is an underrated wildcard. – glenn jackman Sep 20 '11 at 2:58
feedback
find /blah -maxdepth 1 -iname '?????' -xtype f
link|improve this answer
It tells me both maxdepth and iname are bad options. – Kris Sep 19 '11 at 20:24
What version of find? mine was find from gnu findutils-4.4.0. – Dan D. Sep 19 '11 at 20:28
feedback

You can use this:

ls | awk '{if (length($1)==10) print $1}'
link|improve this answer
2  
Unix supported spaces in file names since at least 1980's. – grawity Sep 19 '11 at 21:16
feedback

Your Answer

 
or
required, but never shown