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:
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!
I threw together a little script, maybe there's a better way to do it but seems like it works:
:/]# 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
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...