Unix administration - To display the total file sizes of each user in a common/shared directory (like /tmp)

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > June 2006 > To display the total file sizes of each user in a common/shared directory (like /tmp)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author To display the total file sizes of each user in a common/shared directory (like /tmp)
balreddy.gattu@gmail.com

2006-06-14, 7:22 pm

Hello,
Iam trying to find the size of each user used in a common directory.
Do we have any direct command to get the results?

example: i want to find the total size of each users files under
/tmp.

Thanks,
Gattu

Michael B. Trausch

2006-06-15, 1:28 am

balreddy.gattu@gmail.com wrote in
<1150310986.555812.100360@y41g2000cwy.googlegroups.com> on Wed, June 14
2006 14:49:
>
> Hello,
> Iam trying to find the size of each user used in a common directory.
> Do we have any direct command to get the results?
>
> example: i want to find the total size of each users files under
> /tmp.
>


There are various ways to do this. Under a system that supports filesystem
quotas, merely enabling quotas would allow you to then view the usage by
user/group on the drive. Alternatively, you could use a shell script to
collect the information and partially automate the process for you. For
that, you could probably:

* have the script do an 'ls -lR' on the target directory, cut the user name
out of the list, sort and then uniq it.
* then, loop through that list of users, and have it add the sizes of each
file owned by that user together, presenting each user as it computes it.

How the script does these things is going to vary based on some of the tiny
nuances of your UNIX-like system (e.g., # of spaces in output of 'ls',
whether the filesize is listed in bytes, blocks, or whatever, etc.)

HTH,
Mike

--
Registered Linux User #417338, machine #325045.

....and that is how we know the Earth to be banana-shaped.
Stephane Chazelas

2006-06-15, 7:26 am

On Thu, 15 Jun 2006 05:39:39 GMT, Logan Shaw wrote:
> balreddy.gattu@gmail.com wrote:
>
> Here's one possible way:
>
> cd /tmp && find . -user joebob -type f -print0 |
> xargs -0 du -sk |
> awk '{t+=$1} END {print t}'

[...]

If you're going to use GNU specific features, then

find . ! -name . -printf '%D-%i:%u:%b\n' |
awk -F: '
! ($1 in already_seen) {
size[$2] += $3
already_seen[$1] = ""
}
END {
sort = "sort -t: -k 2rn"
for (i in size) {
printf "%12s: %.17g\n", i, size[i] * 512 | sort
total += size[i]
}
close(sort)
printf "---\n%12s: %.17g\n", "total", total * 512
}'

The output should be consistent with du's:

stephane: 104386560
test: 48738304
root: 81920
---
total: 153206784
$ du -sB1
153206784

--
Stephane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com