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


Click here to return to the 'Counting files in a directory from the terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Counting files in a directory from the terminal
Authored by: sjk on Feb 16, '06 07:37:54PM
That's broken in several ways (unnecessary cat; includes directories; doesn't handle filenames with embedded spaces; matched .jpg anywhere in the filename). Try something like this:

find . -not -type d | egrep -v '\.jpg$' | wc -l

The "-not -type d" excludes directories but would find symlinks and other non-regular files; change it to "-type f" to only find regular files. There should be a single backslash before the dot in the .jpg string for egrep; I always seem to get that quoting wrong here because the preview doesn't match the post.

[ Reply to This | # ]