Solved

Find all directories with over 100,000 files in them

Posted on 2011-02-22
7
240 Views
Last Modified: 2012-05-11
I have a problem where I need to search all the directories on a server and find all the ones with over 100,000 files in them.

This is a Red hat 5.5 system.

Any ideas?
0
Comment
Question by:thomasvincent
7 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 34954524
find / -type d | while read dir
  do
   [ $(find $dir -maxdepth 1 -type f |wc -l) -gt 100000 ] && echo $dir
  done

wmp
0
 
LVL 5

Assisted Solution

by:rysic
rysic earned 250 total points
ID: 34962581
If you need speed, you can use command:

locate

it is indexing files one per day and then find it very fast.

http://linux.about.com/od/commands/l/blcmdl1_locate.htm

If you need to find it only one time and not need speed, use woolmilkporc's way of finding files.
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 34971080
may i also suggest that when you execute the script that you send stderr to dev null otherwise a whole lot of junk may show up

find_big_dirs.sh 2>/dev/null


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:point_pleasant
ID: 34971119
might also sugest making the shell take arguemant for the number of files.


find / -type d | while read dir
  do
   [ $(find $dir -maxdepth 1 -type f |wc -l) -gt $1 ] && echo $dir
  done


then call with

find_big_dirs.sh 10000 2>/dev/null



0
 

Expert Comment

by:peterbieshaar
ID: 34997978
It's not a direct shell script, but perl should work for this quite sufficiently

#!  /usr/bin/perl

open( E_find, "find / -type f | ");

while ( <E_find> ) {
        ( $dir ) = /^(.*)\/[^\/]*$/;
        push( @dirs, $dir ) if ! defined $number{$dir};
        $number{$dir} += 1;
}

foreach ( @dirs ) {
        print "$_ heeft $number{$_} entries ...\n" if $number{$_} > 5;
}
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 36433939
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now