How to count all the files in a directory

2016


Updated Jun 2017


To find all of the files in a folder or directory, use:

  find . -type f | wc -l


The -type f means files

To find all the sub directories, use:

  find . -type d | wc -l


The -type d means directories. Please Note: The directory you are searching in is counted, so even with no sub directories, the count will be 1.




Old



  ls -l -R /path | wc -l



Or:

  find "/home/charles/testarea" -daystart -type f -mtime +6 | wc -l



Or:

#Delete subfolders from “/home/charles/testarea”

#clear terminal window
echo -e “\033c”

find “/home/charles/testarea” -mindepth 1 -mtime +6 -type d | while read x; do echo “———” ; echo Deleting folder “$x” ; rm -R “$x”;

done