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?
views:
89answers:
3
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
2009-11-04 11:04:14
i wouldn't want to use Java just for this. :)
ghostdog74
2009-11-04 11:08:15
Maybe not...I wrote 90% of it before I noticed the lack of a "java" tag, so I posted it anyway.
duffymo
2009-11-04 11:16:16
+6
A:
few ways with GNU find
$ find . -type d -name "?????????????????????????????????"
$ find /path -type d -printf "%f\n" | awk 'length==33'
ghostdog74
2009-11-04 11:06:51
+1 but I think it should be "-type d" to find directories rather than files
Kaze no Koe
2009-11-04 11:16:09
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
2009-11-04 11:53:02
A:
Sure:
find dir -name '?????????????????????????????????'
(that's 33 time ?
).
Aaron Digulla
2009-11-04 11:07:44