Solved

Find all directories with over 100,000 files in them

Posted on 2011-02-22
7
239 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

20 Experts available now in Live!

Get 1:1 Help Now