无法通过ls获取目录的大小
我运行命令未能成功获取目录的大小(内部文件属于目录的大小),
ls -lSrh
我只得到目录大小的千位,而目录的内容却不止于此。
如何通过 ls 列出目录的大小(包括其内容)?
I run the command unsuccessfully to get the size of directories (files inside belong to the size of a directory)
ls -lSrh
I get only kilobits for the size of directories while their content is more than that.
How can you list the size of directories including their content in the number by ls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ls
将为您提供目录条目的大小,而不是目录内容的大小。 根据我对man ls
的快速浏览,似乎没有办法让ls
深入并计算目录的大小(很可能是因为它是昂贵的操作)。ls
is going to give you the size of the directory entry, not of the directory contents. Based on my quick skim ofman ls
there doesn't appear to be a way to makels
dive down and calculate the size of the directories (most likely because it would be an expensive operation).如果你想获取目录大小,你可以使用
If you want to get directories size, you can use
du -hs
非常有用,除非您有一个大目录。例如,如果您存储缓存文件(例如 Rails 的文件系统缓存存储)或上传的文件,...使用分区模式,如“cache/123/456/789/real_files”,并且您有很多这样的文件,
du
花费很长时间,最终阻塞所有 IO。我没有更好的解决方案,但在高峰时间在生产服务器上运行它之前需要考虑这一点。
du -hs
is great until you have a big directory.For example, if you store cache files (for example the filesystem cache store for Rails) or uploaded files, … with a partitioned schema, like "cache/123/456/789/real_files" and you have a lot of them,
du
is taking forever, eventually blocking all IO.I don't have a better solution, but this is to be considered before you run this on production server during peak time.
基于 Sean Bright 的答案,您可以执行以下操作(在 BASH 中)
这将获取当前目录中所有目录的完整目录内容。
Building on Sean Bright's answer you can do the following (in BASH)
This will get a full directory content for all the directories in the current directory.