how to count total number of files in a directory in linux code example Example: How to count number of files in each directory du -a | cut -d/ -f2 | sort | uniq -c | sort -nr