Kamil Dudka wrote: > On Monday 25 of May 2009 15:43:50 Reuben Thomas wrote: >> Hi, >> >> If I do "ls -l |head" on a directory with many files in it, it takes a long >> time to complete, suggesting that it has read the entire directory. Since >> no sorting is involved, why has it done this? > > If you want to turn off sorting, try the -U option.
That's a good start. To do what he wants you have to know that ls -1U is the only way to get one output entry per readdir call. Reuben, you want to do it like this: ls -1U|head|xargs ls -l Note the difference: (#files, create time(s), time to list first 10(s)) $ for i in 10000 50000 100000 200000; do printf "$i "; mkdir $i && (cd $i && seq $i| env time --format %e xargs touch 2>&1 | tr '\n' ' ' ) && (cd $i && env time --format %e ls -lU|head>/dev/null) && (cd $i && seq $i|xargs rm -f); rmdir $i; done 10000 0.38 0.08 50000 1.92 0.37 100000 3.81 0.73 200000 7.60 1.47 $ for i in 10000 50000 100000 200000; do printf "$i "; mkdir $i && (cd $i && seq $i| env time --format %e xargs touch 2>&1 | tr '\n' ' ' && ls -1U|head|env time --format %e xargs ls -l>/dev/null && seq $i|xargs rm -f) && rmdir $i; done 10000 0.39 0.00 50000 1.91 0.00 100000 3.81 0.00 200000 7.63 0.00 _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils