Number of files in each folder of a directory

I have a folder with over 200 sub-folders (no sub-sub-folders). Is there a way to get a list of all of the sub-folders and the number of files contained in each folder? Any help is appreciated.

Example:
Folder A - 25
Folder B - 1
Folder C - 345
etc

From the parent folder in terminal: for dir in */ ; do echo "$dir: $(find "$dir" -type f | wc -l)"; done

If you had sub-subfolders, this would count the total files in the tree for each top level subfolder.

1 Like

This is exactly what I needed. The terminal is fantastic. I don’t know what I’m doing there but I can copy and paste pretty good. :crazy_face:

I wasn’t able to change the directory to /Pictures/mypix:

If I entered “cd /Pictures”, it would change the directory to “Pictures”
If I entered “cd /Pictures/mypix”, it would state it couldn’t find that directory

I ended up just moving “mypix” into my home folder and running your script in the terminal. Worked fine.

Thank you for your help. I appreciate it. Take care.

1 Like

Glad it helped! If Pictures/mypix was in your home folder, you would use ~/ instead of / (but you probably used ~/ to get to ~/mypix so who knows…)

Sorry, this was wrong - to change to the Pictures directory in the Terminal I just entered cd Pictures (no slash). Never could get to the sub-folder mypix within Pictures, so I just moved it into the home folder.

Anyway, you solved my problem and saved me a lot of time. Thanks again. :grinning:

1 Like

Hey, just noticed my problem: mypix had a space at the end of the name, ie "mypix ". When I removed the space at the end of the name I was able to change the directory to mypix as a subfolder in Pictures. This kind of stuff drives me crazy. :crazy_face:

Goodnight. Over and out.

2 Likes

In the terminal you can autocomplete file and folder names. If you type the first few letters of the file/directory (e.g. myp) and then press the tab key it will autocomplete the rest of the location/file you are navigating to. Very handy when you have a file with a very long name that you are trying to open.

1 Like