[英]How to find directories with the name of specific length
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). 例如,我有一堆目录长度等于33个字符('a92e8cc611fdebcca3cf2fc8dc02c918','c442fb3f46d6c8bd17d27245290a9512'等等)。 Does find
utility accepts condition in form of the 'wc -c'? find
实用程序是否接受'wc -c'形式的条件? Or maybe some other utilities should be piped together? 或者也许其他一些工具应该用管道输送?
few ways with GNU find GNU找到的几种方法
$ find . -type d -name "?????????????????????????????????"
$ find /path -type d -printf "%f\n" | awk 'length==33'
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. 您没有Java标记,但是如果您这样做,您可以编写一个FileFilter来封装您考虑的任何条件并将其传递给java.io.File.list()方法。 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. 对不起,这不是* nix脚本。
The Apache Commons IO JAR has some nice file and directory utilities that could make this an easy job. Apache Commons IO JAR有一些很好的文件和目录实用程序,可以使这个工作变得简单。
Sure: 当然:
find dir -name '?????????????????????????????????'
(that's 33 time ?
). (这是33次?
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.