linux - 排除来自 "du"的所有权限被拒绝消息

标签 linux shell warnings suppress-warnings du

我正在尝试评估多个 Unix 用户帐户的磁盘使用情况。 简而言之,我使用以下命令:

du -cBM --max-depth=1 | sort -n

但是我看到了很多像下面这样的错误消息。如何从显示中排除所有此类“权限被拒绝”消息?

du: `./james/.gnome2': Permission denied

我的请求可能与以下列表非常相似,只需将“find”替换为“du”即可。

How can I exclude all "permission denied" messages from "find"?

以下线程不起作用。我想我正在使用 bash。

Excluding hidden files from du command output with --exclude, grep -v or sed

最佳答案

du -cBM --max-depth=1 2>/dev/null | sort -n 

或者在 bash 中更好(只需过滤掉这个特定的错误,而不是像最后一个片段一样)

du -cBM --max-depth=1 2> >(grep -v 'Permission denied') | sort -n 

关于linux - 排除来自 "du"的所有权限被拒绝消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15141588/

相关文章:

linux - 什么是基于 Debian 的发行版?

linux - 如何清理目录结构的文件权限

linux - 如何在带双引号的ssh命令中处理单引号

oauth - 尝试在使用 OAuth 展示器时展示 UINavigationController

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

ios - Facebook iOS SDK FRAMEWORK_SEARCH_PATH

linux - Git 弄乱了 Linux 容器上的非 ASCII 字符

node.js - 如何基于 GitHub webhook 自动化部署 docker?

string - Shell 脚本三元运算符获取字符串结果

c++ - 如何将 makefile 从生成可执行文件更改为生成共享库