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.
I have many directories under /home. What is the fastest way to find who is taking lot of space.
So for this is what I did.
Code:
cd /home
du -sh * |more
The above command takes long time to run. Is there a different command?
My goal is, I want to send email each month how much space is under their directory.
Thanks.
Click here to see the post LQ members have rated as the most helpful post in this thread.
There is no faster alternative to the du command. To accomplish your task it would be advised to create a shell script that does a du of each home directory independently, du does not take much resources and will complete faster if you run a seperate process for each directory. You can then do a test with an if statement or a similar function and email out any directories that are over a certain size.
You can also check with the help of Disk Usage Analyzer. In Gnome it is under Applications --> Accessories --> Disk Usage Analyzer.
That is simply a graphical interface that runs the du command for you. It is more resource intensive(barely) as it uses the x windows system but sam_nyc did state he wants a monthly print out and email automatically.
Try a basic script such as below set up on a monthly cron job and modify it for your needs.
This is a simply for loop but you can make it a better script by doing it in a few different ways, I'm just a bit lazy right now.
Code:
#!/bin/bash
for homedir in $(ls -d /home/*); do du -sh $homedir >> /tmp/$(date +%m-%d-%Y)-home-directory-sizes.txt; done
EMAILMESSAGE=/tmp/$(date +%m-%d-%Y)-home-directory-sizes.txt
SUBJECT=$(date +%m-%d-%Y) Home Directory Usage
SENDTO=youremail@domain.com
/bin/mail -s "$SUBJECT" "$SENDTO" < $EMAILMESSAGE
Set it up as a cron job around 11 P.M. and redirect the output to /dev/null or a text file for logging if you need it. Do not set this up to run at midnight as the date will be different once the du's complete and cause the email to not send correctly.
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Rep:
You can also use this code written in perl:
Quote:
#!/usr/bin/perl
use strict;
use warnings;
use Filesys:: DiskSpace;
my $dir = "/home/*";
my ($fs_type, $fs_desc, $used, $avail, $fused, $favail) = df $dir;
my $df_free = (($avail) / ($avail+$used)) * 100.0;
my $out = sprintf("Disk space on $dir: %0.2f\n",$df_free);
print $out;
Last edited by Satyaveer Arya; 04-09-2012 at 03:51 PM.
I use python over perl but still a decent script if you want to go that route. However, you would want to use du instead of df as it is more accurate and in some cases df can provide very inaccurate results. I've run into several issues where syslog processes where causing df to read higher disk usage by almost 20 GB even though the files it had open were no longer that size.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.