How do I print a list of filenames in Mac OS folders as they appear in Finder using Terminal?

I would like to be able to print a list of the filenames in specific Mac OS (Catalina) folders as they appear in the Finder. I don't believe the GUI has an option for that.


Is there a way to do it with a Terminal command?

If so, can the command be made recursive, so that it includes the filenames of files in the specified parent folder's subfolders?


Thanks.


[Re-Titled by Moderator]

Earlier Mac models

Posted on May 7, 2025 2:46 PM

Reply
Question marked as ⚠️ Top-ranking reply

Posted on May 7, 2025 5:30 PM

ddow77 wrote:

r4lf wrote:

ls -laR '/path/to/folder'
Thanks. Does "path" start with the 'user folder' name or a location higher up than that?


It depends.


A “path” is the term used for a directory specification, or a directory and file specification. A path can be either absolute and starting from root, or it can be relative to the current default directory.


For the simplest case, yes, you can start the path at the / root directory, so it would be:

/Users/{yourshortnamehere}/the/rest/of/the/path 


Though there are wrinkles, the tilde ~ and the variable HOME are the login directory for the current user. The ~ works (“expands”) within the command shell in certain cases, while HOME is a variable that the shell and apps can get at it and its translation.


Which would mean the following syntax can workin most shells:

~/the/rest/of/the/path


There are various descriptions of this around: https://unix.stackexchange.com/questions/125522/path-syntax-rules#125524


To avoid confusion, PATH (usually in uppercase, though shell syntax details vary) is the name of a variable used to define where the command shell will look for executable tools or scripts matching the name given to the shell; where the tools are located.

4 replies
Sort By: 
Question marked as ⚠️ Top-ranking reply

May 7, 2025 5:30 PM in response to ddow77

ddow77 wrote:

r4lf wrote:

ls -laR '/path/to/folder'
Thanks. Does "path" start with the 'user folder' name or a location higher up than that?


It depends.


A “path” is the term used for a directory specification, or a directory and file specification. A path can be either absolute and starting from root, or it can be relative to the current default directory.


For the simplest case, yes, you can start the path at the / root directory, so it would be:

/Users/{yourshortnamehere}/the/rest/of/the/path 


Though there are wrinkles, the tilde ~ and the variable HOME are the login directory for the current user. The ~ works (“expands”) within the command shell in certain cases, while HOME is a variable that the shell and apps can get at it and its translation.


Which would mean the following syntax can workin most shells:

~/the/rest/of/the/path


There are various descriptions of this around: https://unix.stackexchange.com/questions/125522/path-syntax-rules#125524


To avoid confusion, PATH (usually in uppercase, though shell syntax details vary) is the name of a variable used to define where the command shell will look for executable tools or scripts matching the name given to the shell; where the tools are located.

Reply

How do I print a list of filenames in Mac OS folders as they appear in Finder using Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.