To determine how many files there are in the current directory, put in

ls -1 | wc -l.

This uses wc to do a count of the number of lines (-l) in the output of ls -1. It doesn’t count dotfiles, but seems it will count the directory ./

To include subdirectory files, you can use ls -R | wc -l

To ignore directory ./ you can use find . -type f | wc -l

If you want to count only files and NOT include symbolic links (just an example of what else you could do), you could use ls -l | grep -v ^l | wc -l (that’s an “L” not a “1″ this time, we want a “long” listing here). grep checks for any line beginning with “l” (indicating a link), and discards that line (-v).

Add A Comment