Thread View: news.software.nntp
7 messages
7 total messages
Started by Michael Hucka
Wed, 23 Jul 1997 00:00
Quick way to list how many files in a each subdirectory?
Author: Michael Hucka
Date: Wed, 23 Jul 1997 00:00
Date: Wed, 23 Jul 1997 00:00
12 lines
1111 bytes
1111 bytes
Maybe someone can save me the time of inventing this wheel: does anyone have a utility that will walk down a directory tree and list how many files are in each subdirectory? I don't need any other info, just the number of files. (I want to go through the news spool and hunt for bloated directories.) -- Mike Hucka hucka@umich.edu http://www.eecs.umich.edu/~hucka University PhD to be, computational models of human visual processing (AI Lab) of UNIX systems administrator & programmer/analyst (EECS DCO) Michigan
Re: Quick way to list how many files in a each subdirectory?
Author: brian moore
Date: Wed, 23 Jul 1997 00:00
Date: Wed, 23 Jul 1997 00:00
18 lines
1356 bytes
1356 bytes
In article <823ep57gog.fsf@manic.eecs.umich.edu>, Michael Hucka <hucka@eecs.umich.edu> writes: > Maybe someone can save me the time of inventing this wheel: does anyone have > a utility that will walk down a directory tree and list how many files are in > each subdirectory? I don't need any other info, just the number of files. > (I want to go through the news spool and hunt for bloated directories.) How about something like: find /var/spool/news -type d -size +24 -ls -- Brian Moore The opinions expressed above are my own, not Sysadmin, C/Perl Hacker necessarily my employers'.
Re: Quick way to list how many files in a each subdirectory?
Author: Matt Dillon
Date: Wed, 23 Jul 1997 00:00
Date: Wed, 23 Jul 1997 00:00
39 lines
1686 bytes
1686 bytes
:In article <823ep57gog.fsf@manic.eecs.umich.edu>,
:Michael Hucka <hucka@eecs.umich.edu> wrote:
:>Maybe someone can save me the time of inventing this wheel: does anyone have
:>a utility that will walk down a directory tree and list how many files are in
:>each subdirectory? I don't need any other info, just the number of files.
:>(I want to go through the news spool and hunt for bloated directories.)
:>
:>--
:>Mike Hucka hucka@umich.edu http://www.eecs.umich.edu/~hucka University
:> PhD to be, computational models of human visual processing (AI Lab) of
:> UNIX systems administrator & programmer/analyst (EECS DCO) Michigan
You can often find bloat or potential bloat by looking at the size of the
directory itself:
#!/bin/csh -f
#
# or wherever your news spool is
cd /news/spool/news
find . -type d -print >file
foreach i ( `cat file` )
ls -lda $i
end
% ./lsdirs > file2
% sort -n +4 file2
(untested, but something like the above ought to work)
-Matt
Re: Quick way to list how many files in a each subdirectory?
Author: brian moore
Date: Thu, 24 Jul 1997 00:00
Date: Thu, 24 Jul 1997 00:00
35 lines
2518 bytes
2518 bytes
In article <82pvs959be.fsf@manic.eecs.umich.edu>, Michael Hucka <hucka@eecs.umich.edu> writes: >>>>>> On 23 Jul 1997, bem@news.cmc.net (brian moore) wrote: > > bem> How about something like: > bem> find /var/spool/news -type d -size +24 -ls > > At least under Solaris 2.5.x, the size of the directory doesn't directly > correlate with the number of files in it. However, the size does appear to > increase monotonically with the number of files in the directory, so it's > true that you could use this as a rough guide to directory bloat (as Matt > Dillon also pointed out in a separate posting). True, and also true on any other *nix like system I know of. A directory entry is simply a pointer to an inode and the name of the entry. Of course since it's not a linked list, a directory of a hundred 100-byte filenames (roughly 10k) or two hundred 50-byte filenames (also roughly 10k) would take as long to search for a given file if strcmp's were free. (50 byte strcmps are assumed to be cheaper than 100 bytes, but that depends on your data distribution ... if the difference is usually in the first 50 bytes it won't matter much.) And since directories don't get smaller when you delete files, the size of the directory is still a factor even if there are no files listed in it. This is why the various hacks to get around the control/cancel directory structure do things like mv the directory and then rm it, or the better method of splitting the directory into pieces, effectively making it into a B-tree instead of the flat file it usually is. -- Brian Moore The opinions expressed above are my own, not Sysadmin, C/Perl Hacker necesarily my employers'.
Re: Quick way to list how many files in a each subdirectory?
Author: Charles Ball
Date: Thu, 24 Jul 1997 00:00
Date: Thu, 24 Jul 1997 00:00
42 lines
1680 bytes
1680 bytes
You really don't want to use find to traverse a news spool; it will stat each
file looking for directories.
Here's a utility customized for counting articles in a news spool.
It uses $inn::active to identify directories and perl's readdir to return
the number of files in each news spool directory. Like find(1)'s "-ls"
function, this also skips the filename sort.
/news/local/countnewsgroups:
#!/usr/local/bin/perl
require "/news/etc/innshellvars.pl";
use DirHandle;
use FileHandle;
my (%newsgroup, @active, @dir, $dir, $DH, );
my $ACTIVE = new FileHandle "<$inn::active";
while (<$ACTIVE>) {
@active = split;
($dir = $active[0]) =~ s,\.,/,g;
$DH = new DirHandle "$inn::spool/$dir";
next if !defined($DH);
@dir = (readdir($DH));
#set $newsgroup{<groupname>} ::= #articles
$newsgroup{$active[0]} = @dir;
#debugging
#print sprintf "$active[0]: %d\n", scalar(@dir);
}
#print newsgroup article counts in decreasing order
foreach $group (sort {$newsgroup{$b} <=> $newsgroup{$a}} keys %newsgroup) {
print "$group: $newsgroup{$group}\n";
}
Re: Quick way to list how many files in a each subdirectory?
Author: Phil Blanchfield
Date: Thu, 24 Jul 1997 00:00
Date: Thu, 24 Jul 1997 00:00
57 lines
2272 bytes
2272 bytes
In article <823ep57gog.fsf@manic.eecs.umich.edu>,
Michael Hucka <hucka@eecs.umich.edu> wrote:
>Maybe someone can save me the time of inventing this wheel: does anyone have
>a utility that will walk down a directory tree and list how many files are in
>each subdirectory? I don't need any other info, just the number of files.
>(I want to go through the news spool and hunt for bloated directories.)
I needed something like this once and I found that the active file provided
enough info for what I wanted. I came up with the following perl script
which takes:
55.420u 1.290s 3:12.85 29.4% 0+462k 8+2io 13pf+0w
to run on a SPARC-10/41
I hope it helps!
#!/usr/local/bin/perl
#
# active-summary - Practically extract and report on the number
# of messages/files in each group.
#
# This is only approximate as the active file only keeps track of the
# lower and upper bounds. Cancellations and articles with explicit
# expire times can leave holes.
$ACTIVE="/usr/lib/news/active"; # the active file
$LOW_WATER=1000; # don't report on groups with < this many
open(ACTIVE,"$ACTIVE") || die "Can't open active file";
while(<ACTIVE>)
{
($group,$max,$min)=split;
$diff=$max-$min;
if( $diff < $LOW_WATER ) { next; }
$group{$group}=$diff;
@sorted_by_narts = sort by_narts keys(%group);
}
foreach $key ( @sorted_by_narts)
{
print "$key $group{$key}\n";
}
sub by_narts
{
$group{$b} <=> $group{$a};
}
--
Phil Blanchfield
The Communications Research Centre 3701 Carling Avenue, Ottawa Ontario CANADA
Internet: Phil.Blanchfield@CRC.DOC.CA Tel: (613) 998-2761 Fax: (613) 998-9648
Re: Quick way to list how many files in a each subdirectory?
Author: Michael Hucka
Date: Thu, 24 Jul 1997 00:00
Date: Thu, 24 Jul 1997 00:00
18 lines
1408 bytes
1408 bytes
>>>>> On 23 Jul 1997, bem@news.cmc.net (brian moore) wrote: bem> How about something like: bem> find /var/spool/news -type d -size +24 -ls At least under Solaris 2.5.x, the size of the directory doesn't directly correlate with the number of files in it. However, the size does appear to increase monotonically with the number of files in the directory, so it's true that you could use this as a rough guide to directory bloat (as Matt Dillon also pointed out in a separate posting). -- Mike Hucka hucka@umich.edu http://www.eecs.umich.edu/~hucka University PhD to be, computational models of human visual processing (AI Lab) of UNIX systems administrator & programmer/analyst (EECS DCO) Michigan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads