[SunRescue] finding a number of files in a dirB

Kent Rankin krankin at usit.net
Tue Feb 22 02:56:52 CST 2000


> >       Mind you, I also noticed an individual(*grin*) that recommended a "ls |
> > wc -l", but that would potentially produce erroneous results due to the
> > tabulation of files when listed without the long format.  However,
> > credit should be given for not having introduced the ". & .." bug.
> 
>   Nope.  ls knows when its output is being redirected or piped...under
> those circumstances, it prints one filename per line.
> 
>   Try "ls | cat" to demonstrate this.
> 
>   ;-)

	And this, right here, is exactly why I always include a disclaimer. 
Regardless of whether I'm speaking or writing.  *LMAO*

	I hadn't thought of ls' awareness of I/O redirection.  I was familiar
of it(in fact, is anyone familiar with a way to prevent it from doing
that?), as I have always been frustrated by my lack of ability to pipe
tabulated ls'.  *sigh*

	However, the "ls|wc -l" method still doesn't list *ALL* files(files
beginning with a period, in this example).  It does provide for a
line-by-line listing, though.  That's a step in the right direction. 
And since it doesn't list files starting with a period, it doesn't list
. or .. <end of sentence>

	Thus, I come to that point of "two out of three ain't bad".  That
doesn't mean that it does the job.  For listing all non-hidden files, it
works wonders.  But for listing all files in a directory, well... you
know.  *grin*

	Thanks for pointing that out, though.  I had forgotten about the
redirection awareness.


								-Kent Rankin






More information about the rescue mailing list