Solved

Find all directories with over 100,000 files in them

Posted on 2011-02-22
7
243 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
Technology Partners: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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…
Utilizing an array to gracefully append to a list of EmailAddresses
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…

739 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