【问题标题】:How to find the disk usage total of specific files in a directory [closed]如何查找目录中特定文件的磁盘使用总量[关闭]
【发布时间】:2019-06-05 18:53:02
【问题描述】:

所以我有一个目录

/opt/splunk/var/run/

所以我想获取包含 world bundle 或 delta 的运行目录下所有文件的磁盘使用情况

例子:

ls -lrth /opt/splunk/var/run

6726763764-7937483-7237438.bundle (file)
ywueye-7274837-2829383.delta      (file)
serverclass.xml                   (file)
splunk                            (directory)

所以我想要6726763764-7937483-7237438.bundle 和ywueye-7274837-2829383.delta 文件的总磁盘使用量

这可能吗?

【问题讨论】:

标签: linux disk


【解决方案1】:

试试du。这是一个例子

du -sh *.bundl *.delta

总计

du -sch *.bundl *.delta | grep total

【讨论】:

  • 我无法进入我必须执行的目录 sudo du -sch /opt/splunk/var/run/ | grep total 你能改变你对上述场景的回答吗?
  • 在我的终端中对我来说 * 不起作用
【解决方案2】:

您可以尝试使用find 进行复杂搜索,然后使用du 命令计算总大小:


 find /opt/splunk/var/run \( -name "*bundle*" -o -name "*delta*" \) -print0 | du -ch --files0-from=-

或使用正则表达式以获得更短的语法:


find /opt/splunk/var/run -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=-

然后您可以使用grepawk 从输出中仅获取总大小:


 find /opt/splunk/var/run -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=- | grep total | awk '{ print $1 }'

【讨论】:

  • 当我执行你的命令时,它给出了错误——你有太多 ')' 而且 find 也在 Splunk 目录中搜索名为 bundle 的文件(来自我上面的例子)
  • 我的意思是,如果你看到我的例子,在 run 中有一个名为 splunk 的目录。Splunk 目录也有一些文件,它们的名称中包含 bundle。find 命令也列出了它们。我不想要它比运行目录更深入。它应该只考虑运行目录下名称包含 bundle 或 delta 的文件,并给出总磁盘使用情况。
  • 1.我已经修复了路径,因此它将从现在开始使用正确的文件夹。 2. 尝试使用-regex 代替-name 选项的命令。可能是您的 shell 中的 ( 有问题。
  • 仍然进入 splunk 目录
  • 您可以使用 find 命令的-maxdepth 1 选项来限制深度。所以它看起来像find /opt/splunk/var/run -maxdepth 1 -regex '.*\(bundle\|delta\).*' -print0 | du -ch --files0-from=- | grep total | awk '{ print $1 }'
【解决方案3】:

使用du命令如下 du -sh * |grep 捆绑

【讨论】:

    猜你喜欢
    • 2020-02-28
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2013-06-22
    • 2018-10-03
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    相关资源
    最近更新 更多