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 userid
to list files belonging to a specific user. But then how I can get the total file sizes of them?
Check total file size of a specific directory for a specific user
Use awk
ls -lR ./* | grep userid | awk '{sum = sum + $5} END {print sum}'
anyway to get this "human-readable" on the other side? thanks! –
Laborer
@shootingstars Simple version producing human-readable output is
ls -lR ./* | grep userid | awk '{sum = sum + $5} END {printf "%iK\n", sum/1024}'
. Because this is integer math, there is no rounding. You could extend this to MB or GB, but anything more complex than this and I would use Ruby. –
Deloris 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/*
but this one doesn't meet my requirement. We have a group directory which all group members can write to and I want to check how much storage space a specific user has used. Not just their home directory. Thanks anyway. –
Eliason
Use awk
ls -lR ./* | grep userid | awk '{sum = sum + $5} END {print sum}'
anyway to get this "human-readable" on the other side? thanks! –
Laborer
@shootingstars Simple version producing human-readable output is
ls -lR ./* | grep userid | awk '{sum = sum + $5} END {printf "%iK\n", sum/1024}'
. Because this is integer math, there is no rounding. You could extend this to MB or GB, but anything more complex than this and I would use Ruby. –
Deloris © 2022 - 2024 — McMap. All rights reserved.