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: xSmurf on Feb 15, '06 05:04:19PM
I know this topic is about 5 years old but what ever if someone finds it looking for this info (like I did) it might still help. If you are trying to count the # of lines of files in a dir you can use
$ cat `find . | grep -v \.jpg` | wc -l

Note that I made sure I didn't include "data" files, in this case I knew they were all jpg but it might be easier to do the opposite and include only certain extensions.

---
PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf

[ Reply to This | # ]

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 | # ]