find . -maxdepth 1 -type f | less; # check what lines will be counted: comprehensive list of all files in format ./filename find . -maxdepth 1 -type f | wc -l; # count all files in the current directory (excluding folders, excluding symbolic links) # test it mkdir temp cd temp touch 1 2 3 find . -maxdepth 1 -type f | wc -l; # count all files in the current directory 3
actually not precise enough: https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x700.html
in the above test
ls -l | less; # check what lines will be counted # it will also count leading line "total 0" ls -l | wc -l 4
because: this will also count directories!
and prone to errors: “It doesn’t count dotfiles”
also bad:
ls -l | grep -v ^l | less; # check what lines will be counted # it will also count leading line "total 0" ls -l | grep -v ^l | wc -l