How to List All Files and Subdirectory Contents in a Folder on Mac
Ever wanted to see not only every file in a given directory, but all files within that directories buried subdirectories? If you’re looking for what is basically a recursive listing of files in a given folder, we’ll show a great trick for the Mac OS Finder that allows you to do just that, and also demonstrate several more advanced approaches using the command line.
How to Expand All Subdirectories & List Folder Contents in the Mac OS Finder
To quickly see what’s in all the subdirectories of a folder within the Finder, open the parent folder and change to list view. Now you need to hold the Option key and click on the little arrow alongside the name of the directory to expand that directory and all subdirectories at the same time.
The result is that each and every subfolder contained within the directory you option-clicked the arrow on will reveal its contents as well:
Option-clicking that arrow again will cause all subdirectories to close up, otherwise that becomes the new default view when clicking the arrow.
Keep in mind that if you want to view hidden files through this method, you must enable hidden files to be shown in the Mac OS X Finder separately, which will then carry out through every folder until it is disabled again.
The above approach is going to be the easiest method for most users, and the next two methods are focused on the command line and are aimed at those comfortable in the Terminal.
List All Files & Subdirectory Contents from the Command Line
To list all files recursively from the command line, you can attach the -R flag to the traditional ls command. This expands out subdirectories and lists the files contained within them. These commands will work in just about all forms of unix, from Mac OS X to Linux or whatever else you may encounter.
ls -R ~/Desktop/
Sample output would look something like this:
Dark Tower.jpg milky-way.jpg
volcano.jpeg itenerary.txt tickets.JPG
The output is decent, but it could be arranged better.
Using the -lah flags in addition to -R will show permissions, ownership, modification dates, and it makes reading file information much easier. The -a flag is optional, allowing hidden files to be displayed as well.
ls -lahR ~/Desktop/
Sample output would look like:
drwxr-xr-x@ 11 macuser staff 374B Jan 14 15:32 .
drwxr-xr-x 522 macuser staff 17K Jan 28 10:20 ..
-rw-r--r--@ 1 macuser staff 254K Jan 13 15:44 Dark Tower.jpg
-rw-r--r--@ 1 macuser staff 101K Jan 14 15:32 cars.jpg
-rw-r--r--@ 1 macuser staff 141K Jan 13 15:44 star-nebula.jpg
-rw-r--r--@ 1 macuser staff 206K Jan 14 09:57 nintendo.jpg
-rw-r--r--@ 1 macuser staff 134K Jan 13 15:44 m33.jpg
-rw-r--r--@ 1 macuser staff 1.4M Jan 13 15:30 milky-way.jpg
-rw-r--r--@ 1 macuser staff 153K Jan 13 15:44 ngc602.jpg
-rw-r--r--@ 1 macuser staff 194K Jan 13 15:44 windows.jpg
drwxr-xr-x@ 6 macuser staff 204B Dec 9 13:43 .
drwxr-xr-x 522 macuser staff 17K Jan 22 10:20 ..
-rw-r--r--@ 1 macuser staff 6.0K Dec 9 13:43 .DS_Store
-rw-r--r--@ 1 macuser staff 30K Dec 8 12:41 volcano.jpeg
-rw-r--r--@ 1 macuser staff 45K Dec 8 12:41 itinerary.txt
-rw-r--r--@ 1 macuser staff 88K Dec 9 12:31 tickets.JPG
You’ll notice the path to each file is listed above the files themselves, expanding out the subdirectories a lot like the Finder method mentioned up top. You can get the path to proceed the file name though by using a different command entirely.
List All Files Recursively with Full Directory Paths Shown
Finally, if you want a list of all files with their complete paths specified, you can turn to the find command.
find ~/Desktop/Sample/ -type f
This will dump the full path to each file in a listing:
If you’re looking to share a directory listing with someone, the find command likely offers superior results. In such a case, you can dump the output to a file easily by attaching a > to the end like so:
find /Path/To/List -type f > FilesWithPaths.txt
The “-type f” flag signifies regular files only, if you want to show more objects or symbolic links you can check out the man page for find for additional information.