Solved

Find all directories with over 100,000 files in them

Posted on 2011-02-22
7
241 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I monitor a folder and email changes once a day? 12 97
Get a Perl script to return content from a module 7 80
AWS CLI - Instances, Volumes & Tagging 2 94
awk file 6 52
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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