bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ls -l|head seems to look at all files in directory


From: Eric Blake
Subject: Re: ls -l|head seems to look at all files in directory
Date: Mon, 25 May 2009 09:08:42 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Reuben Thomas on 5/25/2009 8:12 AM:
> On Mon, 25 May 2009, Eric Blake wrote:
> 
>> Huh?  Sorting has indeed been done, unless you requested ls -U.
> 
> Indeed, stupid me (and thanks to the others who pointed out my error).
> 
> So, I'll try again:
> 
> ls -lU|head seems to look at all files in directory. It takes just as
> long as ls -l|head, yet it's doing no sorting.

ls -lU will not terminate until it gets a SIGPIPE (or failed write).  So
even though head only printed the first 10 files, ls will continue to
stat() entries until it has populated enough of its stdout pipe to finally
trigger the kernel mechanisms that detect that the head process has quit.
 Depending on how large your directory is, you may end up statting several
hundred files before the ls process will be stopped.  This is yet another
case where the idea of a new coreutil to alter buffering behavior of
subsidiary applications would be advantageous - switching ls over to
line-buffering mode would detect that the head process went away on the
very next file.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoatHoACgkQ84KuGfSFAYAxRwCgmFry8vgHKIsWvam/KP5vDAHW
lBwAoMoX0J3Q3ZOjXiKCf0DAJd3O0p+k
=LdA6
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]