It seems that under most situations ls will read the whole directory before producing any output - typically because it needs to sort or columnise the output. Normally this is fine but when reading a very large directory from a slow network server this effectively causes ls to hang.
Is there a way to get ls to print partial output as it goes along? I've tried the following, on Mac OS X 10.6.8, but they do not appear to work:
ls -lf
ls -1f
Just in case what I want is not clear, the following Perl script does roughly the right thing:
opendir(DIR, ".") or die "can't opendir $dir: $!";
while($filename = readdir DIR) {
print $filename, "\n";
}
closedir DIR;
... only I'd like to be able to use -l
, -lO
, and not have to write it myself!