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 and shell scripting languages 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 11-29-2008 06:21 PM
Expression for Finding Multiple Directories..?? meskue Shell Programming and Scripting 3 07-10-2006 04:04 PM
Finding executable files in all directories CSGUY UNIX for Dummies Questions & Answers 4 04-19-2005 07:34 PM
Finding largest file in current directory? AusTex High Level Programming 1 03-13-2005 01:03 PM
finding directories in UNIX yodaddy UNIX for Dummies Questions & Answers 1 11-08-2001 01:26 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2008
GKnight GKnight is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 35
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!
  #2 (permalink)  
Old 04-29-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,440
man du (-x)
  #3 (permalink)  
Old 04-29-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

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


Code:
du -kx /fs

  #4 (permalink)  
Old 04-30-2008
Mr.Aketi Mr.Aketi is offline
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
  #5 (permalink)  
Old 04-30-2008
GKnight GKnight is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 35
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

  #6 (permalink)  
Old 04-30-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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

  #7 (permalink)  
Old 04-30-2008
GKnight GKnight is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 35
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...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0