Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

add comment

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
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
add comment
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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.