How do I create a list of subdirectories over all mounted drives in terminal?

in macOS edited January 2014
I'm busy debugging a Lua script for Moho. It is a search script to relink media files in a Moho project file. It seems to work well in Windows, but the script author hasn't access to a Mac computer for debugging. I've removed three bugs already, but now I'm stuck, because I lack sufficient knowledge of BASH.

I want to create a list of subdirectories over all mounted disks (including the boot disk), so the script can process it. I need a command to output this list, so I can capture it in a temporary file (using "> mohodlst.dat").


  • Reply 1 of 2
    toweltowel Posts: 1,479member
    You can use the "find" command to list all of the files/directories in a given path that meet specified criteria. For example, to list *all* of the directories in *all* mounted volumes (this will be a *very* long list), do:

    find / -type d

    Replace "/" with a more specific path to restrict find to looking in that directory. You can also search for a directory with a specific name by adding a "name" criterion (with or without wildcards):

    find /Users/SomeUser/ -type d -name "somename*"

    Find's default output is probably exactly the format you want, a simple list of the paths to all matching files/directories, one path per line.
  • Reply 2 of 2
    rashrash Posts: 14member
    Thanks, that was exactly what I needed!

    If you're interested, here is the discussion on the Moho forum that covers my little project:

    Moho General Forum - Exchanging moho files with intact image links

    Edit: Unfortunately, "find" proved not to be compatible with the script (it was written with Windows in mind and Unix support was added without testing). So I had to revert to

    ls -RF1

    and filter out everything but the subdirectory entries (ends with a colon ":").

    I could rewrite the script, but then I would have the problem optimizing it for WinXP (which I don't have). I also couldn't test for Linux.
Sign In or Register to comment.