Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

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

Anything wrong with

ls /blah/?????

As in

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

$ ls blah/?????
blah/apple  blah/pears
share|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
find /blah -maxdepth 1 -iname '?????' -xtype f
share|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

You can use this:

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

You must log in to answer this question.