[SunRescue] finding a number of files in a dirB

Kent Rankin krankin at usit.net
Tue Feb 22 02:11:51 CST 2000


> find . | wc -l
> 
> there might be something simpler too.
> 
> On Mon, 21 Feb 2000, Paul Khoury - Tech Support wrote:
> 
> > What is the command for finding the number files in a given directory
> > (under Solaris)?

	I could be wrong on this one (standard disclaimer  *grin*), but
wouldn't "find ." produce a listing of all directories underneath the
PWD, as well as the given directory?

	Of course, I understand also that . and .. are considered files, but if
the fellow wants to determine the number of files in the directory not
including . and .. , I'm not sure if a "ls -al" would work as well.

	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.

	Thus, to avoid the listing of the current, and previous directory, yet
still provide the long listing format(in order to avoid the miscount due
to tabulation of filenames) I would recommend the following command
line:

		ls -Al|wc -l

The -A switch on ls lists all files whose name starts with a . , yet
excludes the . and .. listings.


								Hope that it helps,
								Kent Rankin






More information about the rescue mailing list