Operating System - HP-UX
1834931 Members
2594 Online
110071 Solutions
New Discussion

Re: how can i check space occupied by each user

 
SOLVED
Go to solution
Namit
Advisor

how can i check space occupied by each user

I need to check the space occupied by different users inside a particular directory. How do I do that ?
Live and let die
14 REPLIES 14
Sandip Ghosh
Honored Contributor

Re: how can i check space occupied by each user

Go to the directory above the User's individual directory and give the command "du -sk *" . It will give you the size in KB.

Sandip
Good Luck!!!
Helen French
Honored Contributor

Re: how can i check space occupied by each user

Try this:

# find dir_name -type f -user user_name | du -k | sort -rn
Life is a promise, fulfill it!
Bruno Vidal
Respected Contributor

Re: how can i check space occupied by each user

It is easy with find/du/awk:
for USER in "liste users"
do
find mydir -user $USER -exec du -sk {} \; | awk 'BEGIN{resu=0}{resu=resu+$1}END{print resu}'
done

Bye
Bruno Vidal
Respected Contributor

Re: how can i check space occupied by each user

oups, sorry, about my answer, should add -type f, or it will count same file more than one.
find . -user $USER -exec du -sk {} \; | awk 'BEGIN{resu=0}{resu=resu+$1}END{print resu}'
Sean OB_1
Honored Contributor

Re: how can i check space occupied by each user

find /dir/to/look/in -type f -user user-to-look-for | du -sk


This will look for all files for one user and the display the usage summary in kilobytes. It will search sub directories also.

Shannon Petry
Honored Contributor

Re: how can i check space occupied by each user

Two words for you. "DISK QUOTAS"

man quota
man quotaed

This is one of them very under used features, which has multiple purposes and makes many things so easy.

Once you setup quotas, all the info is at a command prompt for you to grok.

You do NOT have to set hard or soft limits, so can use quotas for accounting purposes. However, you can set limits to reduce disk pigs effects on your system.

If Im feeling fiesty though, I'll change hard limits to 1K and listen to users complain for an hour ;)

Regards,
Shannon
Microsoft. When do you want a virus today?
Helen French
Honored Contributor

Re: how can i check space occupied by each user

Oops.. please disregard my first post. I did try it and came out with incorrect values.

If you have disk quota enabled on the file system, then use this command:
# quot with -f option
# man quot for details.

Another way is to find the total files owned by the user with the find -user command, then add it up with a script.
Life is a promise, fulfill it!
MANOJ SRIVASTAVA
Honored Contributor

Re: how can i check space occupied by each user

Hi Namit


You may like to do a man diskusg and then list the usage user wise , also ther e is a small script to sort the same usage wise a tthe end of the man


Manoj Srivastava
Namit
Advisor

Re: how can i check space occupied by each user

I have two limitations here ...

First, I want the info about all the users using the directory ( and that includes a lot of them ... so I can't enter the names manually )

Second, I do not have root permissions on the machine.

Is it still possible ?
Sorry for not explaining that before ... I am a dumba** :-(
Live and let die
Anil C. Sedha
Trusted Contributor

Re: how can i check space occupied by each user

Hi,

This can be done easily in the following ways.

If you have all users in a single /home directory, Run this as root.


du -sk /home/*

This will give you each user's disk space utilization.

Regards,
Anil (Don't forget to assing points if answers are valuable to you)
If you need to learn, now is the best opportunity
harry d brown jr
Honored Contributor
Solution

Re: how can i check space occupied by each user


If you don't have root permissions on this machine, then the gathering of this information could be a mute point. If you don't have sufficient permissions to browse these directories then you might as well give up now.

You can't properly gather the size of files in directories where the files are shared amongst other users without reporting the same file over and over again.

I think you need to talk to your systems administrator regarding your concerns on filesystem usage.

live free or die
harry
Live Free or Die
Nag Varma
Advisor

Re: how can i check space occupied by each user

Hi Namit,

This may be of some help..

du -sk /home/* | sort -nr

this sorts the output numerically
and the output is in KB....

Thanks
Nag
S.K. Chan
Honored Contributor

Re: how can i check space occupied by each user

First of all if you do not have root permission, why would you be interested in that kind of info ? That's beside the point .. it's not going to work. All it needs is for someone to close his/her directory access and you (as a normal user) would not be able to traverse it, hence not possible to determine the correct total disk space. If you have root access you can write a script that goes through a for loop one user at a time and accumulate the total at the end.
Shannon Petry
Honored Contributor

Re: how can i check space occupied by each user

Since some programs and users block permissions, I have to agree with Harry that you can not do what you want.

You can have the admin setup 1 of a couple things.
1. Sudo to give you root access to the find command.
* Then you could find all users files, make a script to sort the indes, add the sizes and get useage.

2. setup quotas. This may still require Sudo, but can be setup as a root cron job to mail you out put periodically to fullfill needs as well.

Regards,
Shannon
Microsoft. When do you want a virus today?