Script to monitor directory size of specific users
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
Last edited by eosbuddy; 03-20-2012 at 07:25 AM.
Reason: Update
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.