AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 495176
Accepted
Sergiy Kolodyazhnyy
Sergiy Kolodyazhnyy
Asked: 2019-01-18 14:11:23 +0800 CST2019-01-18 14:11:23 +0800 CST 2019-01-18 14:11:23 +0800 CST

为什么删除条目后具有大量条目的目录不会缩小大小?

  • 772

关闭投票通知:虽然链接的副本提出了相同的问题,但评论和唯一答案并未提供来自权威来源的答案。Thomas Dickey 对我的问题的回答实际上提供了我一直在寻找的答案。因此,建议的副本没有帮助,但是托马斯在这里的回答是正确的。

根据G-Man在此 PerlDuck 的评论中对超级用户问题和个人帐户的回答,具有大量条目的目录的大小超过 4096 字节(可以在输出中看到),但是一旦删除了条目 -数字永远不会下降。ls -l

问题是“为什么”?是否由于ext4文件系统配置为保留目录元数据?显然删除目录并重新创建它不是一个解决方案,因为它会删除原始 inode 并创建一个新的。可以做些什么来手动减少数字?

directory ext4
  • 1 1 个回答
  • 1670 Views

1 个回答

  • Voted
  1. Best Answer
    Thomas Dickey
    2019-01-18T14:29:52+08:002019-01-18T14:29:52+08:00

    引用开发人员的话(在 linux 内核线程中,ext3/ext4 目录在删除大量文件后不会缩小):

    On Thu, May 14, 2009 at 08:45:38PM -0400, Timo Sirainen wrote:
    >
    > I was rather thinking something that I could run while the system was  
    > fully operational. Otherwise just moving the files to a temp directory +
    > rmdir() + rename() would have been fine too.
    >
    > I just tested that xfs, jfs and reiserfs all shrink the directories  
    > immediately. Is it more difficult to implement for ext* or has no one  
    > else found this to be a problem?
    
    It's probably fairest to say no one has thought it worth the effort.
    It would require some fancy games to swap out block locations in the
    extent trees (life would be easier with non-extent-using inodes), and
    in the case of htree, we would have to keep track of the index block
    so we could remove it from the htree index.  So it's all doable, if a
    bit tricky in terms of the technical details; it's just that the
    people who could do it have been busy enough with other things.
    
    It's hasn't been considered high priority because most of the time
    directories don't go from holding thousands of files down to a small
    handful.  
    
                                                    - Ted
    
    • 18

相关问题

  • rm: 无法删除目录 <some/sub/directory>: 设备忙

  • dirs -v 不列出目录堆栈?

  • fsync 如何处理目录链接?

  • 如何使用bash删除目录中的所有文件夹?

  • 确定自上次以来目录内容是否已更改的最快方法

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve