The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
largest field , awk , help jkl_jkl Shell Programming and Scripting 6 3 Days Ago 03:21 PM
Expression for Finding Multiple Directories..?? meskue Shell Programming and Scripting 3 07-10-2006 12:04 PM
Finding executable files in all directories CSGUY UNIX for Dummies Questions & Answers 4 04-19-2005 03:34 PM
Finding largest file in current directory? AusTex High Level Programming 1 03-13-2005 10:03 AM
finding directories in UNIX yodaddy UNIX for Dummies Questions & Answers 1 11-08-2001 10:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-29-2008
Registered User
 

Join Date: Nov 2005
Posts: 24
finding largest directories in a filesystem

I'm trying to come up with a way of finding largest directories in a filesystem (let's say filesystems is running ot of space and I need to find what is consuming all the space). If a directory is a single filesystem, then it's easy, I just run "du -sk *| sort -nr". But the problem is, if some subdirectories are on separate filesystems, then it will show those as well. It's especially hard to get filesystem usage on / since I have many filesystems on some boxes. I tried "du -skx *" but it still shows directories in child filesystems. Then I tried to do it with find command:

Code:
find . -xdev -type d -exec du -sk {} \; | sort -nr | head -10
Despite -xdev switch, I still get the child filesystems in the output. Is there another way of accomplishing this? I'm a bit stumped at the moment. Any advice will be appreciated!
Reply With Quote
Forum Sponsor
  #2  
Old 04-29-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 736
man du (-x)
Reply With Quote
  #3  
Old 04-29-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
Replace "*" with the name of the largest filesystem.

Code:
du -kx /fs
Reply With Quote
  #4  
Old 04-29-2008
Registered User
 

Join Date: Oct 2007
Posts: 7
Hi,

You can check the largest files under directories and subdirectories by using the following command.

ls -lR | sort +4 -5nr | head -10

R -- will check the files under subdirectories


Thanks,
Aketi
Reply With Quote
  #5  
Old 04-30-2008
Registered User
 

Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by shamrock View Post
Replace "*" with the name of the largest filesystem.

Code:
du -kx /fs
Thanks, this works! Gives me a bit too much info though (I only really want to see parent directories, not subdirectories):

Code:
:/]# du -kx / |sort -nr|head -10
5312843 /
4527973 /usr
1951796 /usr/lib
1735880 /usr/share
952800  /usr/lib/ooo-1.1
743964  /usr/lib/ooo-1.1/program
613476  /usr/lib/ooo-1.1/program/resource
381064  /usr/share/doc
310004  /opt
284383  /var
I threw together a little script, maybe there's a better way to do it but seems like it works:

Code:
:/]# for DIR in `ls -1`; do mount | grep /"$DIR" | grep -v /"$DIR"/ > /dev/null || du -skx $DIR; done |sort -nr|head
4527973 usr
310004  opt
284383  var
85468   lib
62344   etc
19056   RedHat
15580   sbin
1668    tmp
468     media
200     dev
Reply With Quote
  #6  
Old 04-30-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The ls in backticks is not really Useful. I guess you can also cut out the second grep by anchoring the end of the search string.

Code:
for DIR in *; do
   mount | grep /"$DIR$" > /dev/null || du -skx "$DIR";
done |sort -nr|head
Reply With Quote
  #7  
Old 04-30-2008
Registered User
 

Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by era View Post
The ls in backticks is not really Useful. I guess you can also cut out the second grep by anchoring the end of the search string.

Code:
for DIR in *; do
   mount | grep /"$DIR$" > /dev/null || du -skx "$DIR";
done |sort -nr|head
Thanks... I was originally using "find" and when I realized it wasn't doing me any good I switched to "ls". I forgot I can just use a wild card

The grep situation is a bit tricky. I'm really looking for a string in the "mount" output that does "not" have / at the end. For example, if I'm at / and have a filesystem mounted at /ks-images/rhel4, I still want to include /ks-images in my output. So came up with a stupid trick of first looking for "/ks-images" and then looking for anything that doesn't match "/ks-images/". "$" doesn't help, in fact the mount point is not even at the end of the line. I'm sure there's a better way, I could use help with this...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0