views:

89

answers:

3

How could I find directories with the name of specific length? For example, I have bunch of directories which have length of the name equal to 33 chars ('a92e8cc611fdebcca3cf2fc8dc02c918', 'c442fb3f46d6c8bd17d27245290a9512' and so on). Does find utility accepts condition in form of the 'wc -c'? Or maybe some other utilities should be piped together?

A: 

You don't have a Java tag, but if you did you'd write a FileFilter to encapsulate whatever criteria you have in mind and pass it to the java.io.File.list() method. If you want to traverse the entire directory structure tree you'll have to recurse, but it's entirely doable.

Sorry, it's just not *nix scripting.

The Apache Commons IO JAR has some nice file and directory utilities that could make this an easy job.

duffymo
i wouldn't want to use Java just for this. :)
ghostdog74
Maybe not...I wrote 90% of it before I noticed the lack of a "java" tag, so I posted it anyway.
duffymo
+6  A: 

few ways with GNU find

$ find . -type d -name "?????????????????????????????????"

$ find /path -type d -printf "%f\n" | awk 'length==33'
ghostdog74
+1 but I think it should be "-type d" to find directories rather than files
Kaze no Koe
find . -regextype posix-extended -type d -regex ".{5}"
mhaller
aeh sorry, use 35 instead of 5. you need to count the leading "./"
mhaller
note that -regex match on the whole path. Therefore using -regex will not work if i start to find from a directory like for example: find /path -regextype posix-extended -type d -regex ".{35}" and not current directory
ghostdog74
A: 

Sure:

find dir -name '?????????????????????????????????'

(that's 33 time ?).

Aaron Digulla