Comments on How to get number of files in directory
Parent
Post
+1
−0
The obvious way to do it is:
- Find some way to get a list of the files
- Pipe it into
wc
to count
Classically, this would be find /path/to/dir | wc
. However fd
does the same thing with better usability. By default, fd
will skip "hidden" files and directories (like .foo
) and will include both files and directories.
Both behaviors can be changed by finding the appropriate CLI arguments in man fd
. However, if you are in a hurry, there's no need to overcomplicate it:
fd | grep -v '/$' | wc
/$
is a regex meaning "ends with /
" and -v
is short for --invert-match
.
0 comment threads