从大型平面目录列表生成目录树
假设我的文件系统中有一个目录,其中包含许多子目录和文件。该目录下的子目录和文件数量多达数万个。您将熟悉尝试查看此目录的内容时会遇到的严重延迟,即使是在终端中也是如此。
我在很多地方都看到过这个解决方案:将顶级内容列表排序到 trie 样式的目录结构中。因此,例如,如果原始列表是 [000000.txt ... 999999.txt],那么要访问文件 012345.txt,我将访问 ./0/1/2/3/4/ 012345.txt。
我一直找不到一个简短而甜蜜的脚本来生成这种结构。是否存在某些东西或者我必须自己编写?我希望它像这样工作:
$ ls
000001.txt 000002.txt ...
$ mktrie
$ ls
0/ 1/ 2/ ...
$
Let's say I have one directory in my filesystem, which has a number of subdirectories and files. The number of subdirectories and files in this directory runs to many tens of thousands. You'll be familiar with the significant delay you'll get in attempting to view the contents of this directory, even in a terminal.
I've seen this solution in a fair number of places: sorting that top-level list of contents into a trie-style directory structure. So, for example, if the original list was [000000.txt ... 999999.txt], then to get to the file 012345.txt, I would visit, say, ./0/1/2/3/4/012345.txt .
What I've been unable to find is a short and sweet script to generate this kind of structure. Does something exist or must I write my own? I'd like it to work like this:
$ ls
000001.txt 000002.txt ...
$ mktrie
$ ls
0/ 1/ 2/ ...
$
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论