Solved

Find all directories with over 100,000 files in them

Posted on 2011-02-22
7
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

761 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