Generating a summary of files and sub-directories

We can generate a list of subdirectories, and the number of files in them, with a combination of the find command, echo, and wc commands, which will be discussed in greater detail in the next chapter.

Use the following to get a summary of files in the current folder:

for d in `find . -type d`;  
  do  
  echo `find $d -type f | wc -l` files in $d;  
done 

If this script is run in /var/log, it will generate output like this:

103 files in .
17 files in ./cups
0 files in ./hp
0 files in ./hp/tmp