无法通过ls获取目录的大小

发布于 2024-07-15 04:12:50 字数 165 浏览 6 评论 0原文

我运行命令未能成功获取目录的大小(内部文件属于目录的大小),

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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小镇女孩 2024-07-22 04:12:50
du -sh directory_name

ls 将为您提供目录条目的大小,而不是目录内容的大小。 根据我对 man ls 的快速浏览,似乎没有办法让 ls 深入并计算目录的大小(很可能是因为它是昂贵的操作)。

du -sh directory_name

ls is going to give you the size of the directory entry, not of the directory contents. Based on my quick skim of man ls there doesn't appear to be a way to make ls dive down and calculate the size of the directories (most likely because it would be an expensive operation).

安人多梦 2024-07-22 04:12:50

如果你想获取目录大小,你可以使用

du -sh

If you want to get directories size, you can use

du -sh
谁把谁当真 2024-07-22 04:12:50

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.

苄①跕圉湢 2024-07-22 04:12:50

基于 Sean Bright 的答案,您可以执行以下操作(在 BASH 中)

for each in $(echo */ | sed "s/ /\n/g" | sed "s/\///g");  do du -hs "$each"; done;

这将获取当前目录中所有目录的完整目录内容。

Building on Sean Bright's answer you can do the following (in BASH)

for each in $(echo */ | sed "s/ /\n/g" | sed "s/\///g");  do du -hs "$each"; done;

This will get a full directory content for all the directories in the current directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文