I came up with the following snippet for counting files in each subdirectory:
for x (**/*(/)); do print $x; find $x -maxdepth 1 -type f | wc -l; done
The command outputs consecutive pairs (one below the other) as follows:
directory_name # of files
I would like to change the code above to:
- Print each match on the same line (i.e.
directory_name ':' # of files)
- Only count files if the folders are leaves in the directory tree (i.e. they don't have any subfolders).
How can I do that?