On Fri, Sep 15, 2000 at 01:27:37PM -0700, Jim Cunning wrote:
| > >can't think today...how doe one count the number of files within a
| > >directory...yes I know du, df, and wc for words in a file.  
| > ls -a | wc -w
| This one works for the most part, but has a subtle problem:  Files
| with spaces in their names get counted multiple times (because wc -w
| counts words instead of lines).  Use the "wc -l" form.

Well, if we're going to get that picky, that will break with file with
newline in their names (which is legal, if a bit perverse).

Here's another approach:

        ( set x *; shift; echo $# )

The leading "x" is in case the first filename starts with a dash (and
the "shift" is to throw the "x" away), and the subshell is to avoid
mucking with your command line argument list.

If course, this has its own problems - no file beginning with "." and if the
directory is empty you'll get a "1" because the "*" is left on the command
line untouched in that case.

Of course, in most circumstances you'll be working with file in some
application domain (MH mail files or source code or whatever, in which case
you know a fair bit about their names anyway.

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

What do _you_ care what other people think?     - Richard Feynman



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to