ls -l takes a forever to finish.

Bill Moran wmoran at
Thu Nov 29 05:42:47 PST 2007

In response to Wojciech Puchar <wojtek at>:

> > ls | wc
> strange. i did
> [wojtek at wojtek ~/b]$ a=0;while [ $a -lt 10000 ];do mkdir $a;a=$[a+1];done
> completed <25 seconds on 1Ghz CPU
> ls takes 0.1 seconds user time, ls -l takes 0.3 second user time.
> unless you have 486/33 or slower system there is something wrong.

Another possible scenario is that the directory is badly fragmented.
Unless something has changed since I last researched this (which is
possible) FreeBSD doesn't manage directory fragmentation during use.
If you're constantly adding and removing files, it's possible that
the directory entry is such a mess that it takes ls a long time to
process it.

Of course, Wojciech's test won't demonstrate this, as the directory is
freshly created, even to the point that the filenames are actually in
alpha order in the directory.

One method to test this would be to tar up the directory and extract
it somewhere else on the machine (assuming you have enough space to do
so).  If the newly created directory doesn't have the problem, it's
likely that the directory entry has become a mess.  Use ls -l to
compare the sizes of the actual directories themselves as a little

Anyway, if that turns out to be the problem, you can fix it by taring
the directory and then restoring it from the tarfile.  Not an ideal
solution, mind you.

Bill Moran

More information about the freebsd-questions mailing list