2

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.

0

3 Answers 3

10

Anything wrong with

ls /blah/?????

As in

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

$ ls blah/?????
blah/apple  blah/pears
1
  • +1 ? is an underrated wildcard. Sep 20, 2011 at 2:58
5
find /blah -maxdepth 1 -iname '?????' -xtype f
3
  • It tells me both maxdepth and iname are bad options.
    – Kris
    Sep 19, 2011 at 20:24
  • What version of find? mine was find from gnu findutils-4.4.0.
    – Dan D.
    Sep 19, 2011 at 20:28
  • Doesn't need to be iname (case insensitive) if all you are matching is wildcards... Otherwise, exactly what i was looking for.
    – Lucas
    Aug 18, 2016 at 22:23
0

You can use this:

ls | awk '{if (length($1)==10) print $1}'
1
  • 3
    Unix supported spaces in file names since at least 1980's. Sep 19, 2011 at 21:16

You must log in to answer this question.