finding largest directories in a filesystem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding largest directories in a filesystem
# 1  
Old 04-29-2008
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  
Old 04-29-2008
man du (-x)
# 3  
Old 04-29-2008
Replace "*" with the name of the largest filesystem.

Code:
du -kx /fs

# 4  
Old 04-30-2008
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  
Old 04-30-2008
Quote:
Originally Posted by shamrock
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  
Old 04-30-2008
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  
Old 04-30-2008
Quote:
Originally Posted by era
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 Smilie

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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding largest files takes too long

Good evening. because the folder has thousand of files it takes too long and have some trouble to get the largest files and then compress files or delete it, for instance find . -size +10000000c -exec ls -ld {} \; |sort -k5n | grep -v .gz The above commad took an hour and i have to cancel... (10 Replies)
Discussion started by: alexcol
10 Replies

2. UNIX for Beginners Questions & Answers

Display largest files in multiple directories

Trying to locate the 25 largest files with read/execute world permissions to be displayed from a combination of 4 different directories. I'm rather new at UNIX and trying to learn the basics. This is what I have come up with so far: find /dir1 /dir2 /dir3 /dir4 -perm -u+rx | sort -nr | head... (1 Reply)
Discussion started by: malk71
1 Replies

3. UNIX for Dummies Questions & Answers

Finding Files only under a specific FileSystem

Hi, I am using AIX and one of my file systems is getting filled up and I need to track with files are occupying more volume. Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/nhdb_lv 2110.00 63.80 97% 76525 1% /nhdb under the Mount Point /nhdb... (1 Reply)
Discussion started by: zulfi123786
1 Replies

4. Shell Programming and Scripting

How to display only Directories in filesystem?

Hi, I want to display only directories inside a particular file system. TIA (2 Replies)
Discussion started by: sumanthupar
2 Replies

5. Shell Programming and Scripting

Finding directories with expression

Hi All, I need your help in finding pattern of directories. need to search for all pattern have "mypatern" from base directory folder. example ------- server1 - base directory 100 server1/ab_123456_1/mypattern 100 server1/ab_123456_2/mypattern 200 server1/ab_123457_1/mypattern... (13 Replies)
Discussion started by: lxdorney
13 Replies

6. UNIX for Dummies Questions & Answers

Finding size of all directories

Alright so I've tried a couple different things that at first glance, looked like they worked. find . -maxdepth 5 -type d -daystart -mtime 1 | xargs du -h Which seems to ignore the previous commands such as depth and modified time. find .. -maxdepth 2 -type d -daystart -ctime 1 | xargs... (8 Replies)
Discussion started by: Aussiemick
8 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

9. Programming

Finding largest file in current directory?

I was hoping to get some assistance with this C program I am working on. The goal is to find the largest file in the current directory and then display this filename along with the filesize. What I have so far will display all the files in the current directory. But, how do I deal with "grabbing"... (1 Reply)
Discussion started by: AusTex
1 Replies

10. UNIX for Dummies Questions & Answers

finding directories in UNIX

I am accessing a UNIX server via FTP. I want to retieve a file in a directory. What is the UNIX command that I need to view and retrieve files from a directory? (1 Reply)
Discussion started by: yodaddy
1 Replies
Login or Register to Ask a Question