Published in: Bash
URL: http://forums.macosxhints.com/archive/index.php/t-19754.html
How many files are in the current working directory? This is recursive, so the count includes subdirectories and files contained in subdirectories. To get a non-recursive count of just the files/directories in the current working directory, use ls -1 in place of find .
find . | wc -l
Comments
Subscribe to comments
You need to login to post a comment.

It will count also directories, including "." and "..". The "ls" solution can take too long on huge directories because it will unnecessarily read in the entire list of file names and sort them. To avoid the "sort" yougehttp://www.google.com/reader/view/in/ can add "-U" The "ls" solution will skip files beginning with "." unless adding "-A".
I have perl script at work which does this with all sorts of bells and whistles, but just to demonstrate a point I'll upload a simple version I wrote right now (no access to the full script right now).