Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'File Count using Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
File Count using Terminal
Authored by: ashevin on Apr 10, '02 03:16:19PM
Hi, "ls -R | wc -l" will not work because one, the contents of each directory are printed multiple entries per line, and two, ls includes information and blank lines that leads to an incorrect total. The closest I can get with a simple ls variant is "ls -1R | grep -v ^$ | grep -v :$ | wc -l", but this only works if none of the files or subdirectories end with a colon. - Avi

[ Reply to This | # ]
Re: File Count using Terminal
Authored by: sjk on Apr 11, '02 04:56:27PM
Sorry, trivial examples disprove that. The default style for ls is one-entry-per-line when output isn't sent to the terminal and you can force that using the -1 (minus one) option; read the man page. Also look at -A, noting the difference between it and -a.

A fast way to count files is by utilizing the locate command. Simple example to count one user's files:

locate /Users/me/ | wc -l

See my comment in Finding files with 'locate' about locate.db permission issues which affect results of this.


[ Reply to This | # ]