Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 03-20-2012, 06:10 AM   #1
LQ Newbie
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
Script to monitor directory size of specific users

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.


Last edited by nicksrulz; 03-28-2012 at 05:21 AM.
Old 03-20-2012, 08:05 AM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,043
Blog Entries: 14

Rep: Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212Reputation: 1212
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.
Old 03-20-2012, 08:19 AM   #3
Registered: Feb 2012
Location: India
Distribution: Ubuntu, Fedora, Gentoo, Mandrake, RedHat, CentOs
Posts: 30

Rep: Reputation: Disabled
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 08:25 AM. Reason: Update


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
assign disk quota or size limit to a specific directory or folder on fedora abhijit_mohanta Linux - General 2 08-10-2009 04:04 AM
downland limit size for specific users cb777 Linux - Newbie 1 02-26-2009 10:51 AM
Monitor directory size in real-time billygoat32 Linux - Software 2 10-28-2005 10:21 AM
Limit Users Home Directory Size KrGAce Linux - Newbie 6 10-24-2005 10:48 AM
wu-ftp confine real users to a specific directory thb Linux - Networking 1 02-06-2002 08:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration