To count the number of files in a directory, I typically use
ls directory | wc -l
But is there another command that doesn't use wc ?
this is one:
ls -l . | egrep -c '^-'
Note:
ls -1 | wc -l
Which means:
ls: list files in dir
-1: (that's a ONE) only one entry per line. Change it to -1a if you want hidden files too
|: pipe output onto...
wc: "wordcount"
-l: count lines.
ls -l returns an additional line at the top adding up the file sizes for a total amount. You should use ls -1 and not the ls -l. Also if one wants hidden files but without the directories . and .. you should use ls -1A | wc -lfind . -type f -printf "." | wc -cls?
wcthat prevents you from using it?treecommand. It will give you the tree and at the bottom tell you how many files and directories there are. If you want hidden files also usetree -a.\nin the file name? Yes, extremely unlikely! But still technically valid and possible.