Recursively print folder contents via the Terminal

Feb 13, '04 11:03:00AM

Contributed by: wallyfoo

My mother-in-law was working on material for a slideshow of images for a friend, and she had painstakingly sub-categorized a ton of images before she realized she needed to resize them all to web size before she sent them along. iPhoto to the rescue! A quick import and export to a new folder later she had web-sized images to zip up and post to a ftp server, but iPhoto had stripped her organization folders. She needed to send the files and their organization to their friend, but didn't have time to reorganize. UNIX to the rescue!

Open up a terminal window and type:

'cd '
(without the quotes and with a space at the end), then drag the folder you want recursively listed to the terminal window and let it finish the path. Hit return.

Next command:
ls -RF > ~/Desktop/folder_list.txt
The -R flag drills recursively into sub folders.
The -F flag writes a trailing slash '/' after folders, and a trailing asterisk '*' after executable files.
folder_list.txt is the name of the file you want the output of the recursive ls command to write out to. Feel free to use something more descriptive as you wish.

When you're done, you'll have a nice plain text file containing the output of the folder structure on your desktop, suitable for copying and pasting or emailing to the recipient of your mangled folder structure.

Comments (18)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004020716455773