Linux 检查特定用户的特定目录的总文件大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6644722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:02:52  来源:igfitidea点击:

Check total file size of a specific directory for a specific user

linuxcommandfilesize

提问by Ken

I want to check how much of the total file storage for a specific user has been used on a specific directory. I am using ls -lR ./* | grep useridto list files belonging to a specific user. But then how I can get the total file sizes of them?

我想检查在特定目录上使用了特定用户的总文件存储量。我正在使用ls -lR ./* | grep userid列出属于特定用户的文件。但是我怎么能得到它们的总文件大小呢?

采纳答案by Ray Baxter

Use awk

使用 awk

ls -lR ./* | grep userid | awk '{sum = sum + } END {print sum}'

回答by Moe Matar

You can do something like this, which will show you the size if each directory in the users home directory, and will print a total size of their home directory at the end (sum of all sub-directories).

你可以做这样的事情,它会显示用户主目录中每个目录的大小,并在最后打印他们的主目录的总大小(所有子目录的总和)。

du -sch /home/USER/*