Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JUMA55

macrumors member
Original poster
Feb 18, 2008
84
41
Does anyone know of a simple program to count folders within folders? Thank you.
 

KALLT

macrumors 603
Sep 23, 2008
5,380
3,415
Can you give more information about what you are trying to achieve?

There are simple Terminal commands that can help you, e.g. find ~/Library -type d | wc -l (which gives you the number of all the folders in the user library directory)
 

JUMA55

macrumors member
Original poster
Feb 18, 2008
84
41
Thank you for the quick reply. How does one get Terminal to find the directory on an external drive?
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
find /Volumes/<drive name>/<folder name> -type d | wc -l

Example:
find /Volumes/My\ Drive/misc -type d | wc -l​
 
Last edited:

KALLT

macrumors 603
Sep 23, 2008
5,380
3,415
Thank you for the quick reply. How does one get Terminal to find the directory on an external drive?

External drives are mounted at the /Volumes path. There are multiple ways to get at the folder you want:
  • Drag the folder you want to search and drop it into the Terminal window; it will be converted into a path
  • Right-click on the folder and hold down the option key, then select “Copy … as Pathname” and paste it into the Terminal window
  • Go the System Preferences → Keyboard → Shortcuts → Services and enable “New Terminal at Folder” or “New Terminal Tab at Folder”; you can now right-click on any folder to open it directly in Terminal (see below), then use find . -type d | wc -l to search within the folder
  • Use ls to find the folder within the command line, e. g. ls /Volumes/MyVolume

Screenshot 2020-06-11 at 16.53.56.png
 

JUMA55

macrumors member
Original poster
Feb 18, 2008
84
41
I had this working a couple of months ago. Now when I use the various commands above to switch to the folder on an external drive, Terminal returns "zsh: permission denied:" What am I doing wrong. Thank you.
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
I had this working a couple of months ago. Now when I use the various commands above to switch to the folder on an external drive, Terminal returns "zsh: permission denied:" What am I doing wrong. Thank you.

This is about permissions. You don't have permissions to access the subfolder in the folder. Note the path that is printed where it reports permission denied, open a Finder window, browse to the folder path, backup to its parent, press command-key I-key, look at the under Sharing & Permissions and see what it says. Unless the permissions allow you access the subfolder you, you will get permission denied:
  • Your username is in the list.
  • everyone permission is not No Access.
  • staff group is listed and is not No Access.
 

JUMA55

macrumors member
Original poster
Feb 18, 2008
84
41
Thank you for the reply. I don't think permissions is the problem. I read and write files from and to that folder all day long. The permissions to that folder are:

pae (Me) - Read & write
staff - Read only
everyone - Read only
 

Taz Mangus

macrumors 604
Mar 10, 2011
7,815
3,504
Thank you for the reply. I don't think permissions is the problem. I read and write files from and to that folder all day long. The permissions to that folder are:

pae (Me) - Read & write
staff - Read only
everyone - Read only

I would like to verify one other thing. Open Terminal:
  1. Enter: ls -l
  2. Enter: <space key>
  3. Copy path reported in error message (command-key c-key).
  4. Enter: <command-key v-key>/..
What is shown in the results of ls command for the folder enter reported in the error message? I wanted to see if there is a difference in what shell “sees” for the permissions vs Finder.
 
Last edited:

JUMA55

macrumors member
Original poster
Feb 18, 2008
84
41
I finally figured it out. I had renamed the folder using a space as the first letter so it would appear first. Now why one minute Terminal would say it couldn't find the folder and the next say permission denied, I have no idea.

This works:

find /Volumes/2big/Music/MP3 -type d | wc -l

as long as I rename "[space]MP3" to just "MP3." If I didn't want to rename the folder what would I put in for the space.

Thank you.
 

sunef

macrumors newbie
Mar 26, 2019
7
1
Hi

You have to quote the directory string or else "escape" the space

~ % mkdir "Music/ MP3/subdir"
~ % find "Music/ MP3" -d
Music/ MP3/subdir
Music/ MP3

~ % find Music/\ MP3 -d
Music/ MP3/subdir
Music/ MP3

Regards
Sune Falck
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.