LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to monitor directory size of specific users (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-monitor-directory-size-of-specific-users-935432/)

nicksrulz 03-20-2012 05:10 AM

Script to monitor directory size of specific users
 
Hi,
I want to write a script that display the size of directories created by specfic users for e.g
ls -ltr command it shows something like this~
ls -ltr
drw-r--r-- 1 abc eng 396 Jun 13 2012 xyz
drwxr-xr-x 1 def eng 202 Aug 15 2012 pqr
drwxr-xr-x 1 ghi eng 201 Aug 15 2012 stu

Now i want to write a script which can monitor size used by users abc,def and ghi to create directories xyz,pqr and stu.

Thanks,
Nitin

MensaWater 03-20-2012 07:05 AM

That's a tad confusing.

xyz, pqr and stu are NOT directories - they are regular files (notice the absence of the "d".

You can determine directory size with the du command:

du -sh <directory>

The -s tells it to summarize (otherwise it would give size of each file in the directory) and the -h tells it to make it human readable. You might want to use -k to get standard size in KB for each entry rather than variable (KB, MB, GB etc...) as reported by -h. Type "man du" for more information.

eosbuddy 03-20-2012 07:19 AM

Code:

for i in `ls /home`; do find /home/$i -maxdepth 1 -type d -ctime -2 | xargs du -sh ; done
You can drop the ctime directive if it is not needed (will give you more lines of output and particularly if you're going to monitor on a day to day basis, you might want it to be there).
Also, the maxdepth can be tweaked or dropped as per your requirement (particularly if you want to know the size of subdirectories further down).


All times are GMT -5. The time now is 10:56 PM.