从大型平面目录列表生成目录树

发布于 2024-08-16 06:19:18 字数 378 浏览 1 评论 0原文

假设我的文件系统中有一个目录,其中包含许多子目录和文件。该目录下的子目录和文件数量多达数万个。您将熟悉尝试查看此目录的内容时会遇到的严重延迟,即使是在终端中也是如此。

我在很多地方都看到过这个解决方案:将顶级内容列表排序到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文