Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Recursively print folder contents via the Terminal UNIX
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.
    •    
  • Currently 3.00 / 5
  You rated: 4 / 5 (5 votes cast)
 
[26,885 views]  

Recursively print folder contents via the Terminal | 18 comments | Create New Account
Click here to return to the 'Recursively print folder contents via the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Recursively print folder contents via the Terminal
Authored by: randalla on Feb 13, '04 11:15:51AM

If you think that's fun, you should check out mkbom and lsbom in the man pages. Those are the tools to create the .pkg files Apple uses for it's installers. You can create a list that stores all information, such as owner, group, file permissions, dates, checksum, etc. It's pretty simple to make one:

mkbom ~user /user.bom

and to read it:

lsbom /user.bom

There's a lot of options you can use with it. Enjoy.



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: imageworx on Feb 13, '04 12:26:24PM

I wonder if a drag-drop script could be made of this?

I know some folks that are designers and they are frustrated at how difficult its been to print out a small TOC of the files they have to burn to CD/DVD-R.

(I don't know about scripting...make it painless please!)

Great tip!

---
To BeOS or Not to BeOS



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: foobar104 on Feb 13, '04 01:37:45PM

Open a window with the contents of the disc showing.

Command-control-shift 4. Sweep out the part of the screen where the listing is.

Open Preview. Choose "New from clipboard" from the File menu.

Print.



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: maddys_daddy on Feb 13, '04 04:37:38PM

This is nice, but it isn't practical if you want to list all the contents of subfolders recursively. This is just a screenshot, not a content listing. That keyboard shortcut is a nice new trick for me, though. May come in handy elsewhere.



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: ngb on Feb 13, '04 06:16:11PM

Only Command-Shift-4 is needed. The Control key is not needed. If you press Space after enabling the screen capture, the cursor turns into a camera. You can then click on a window and only that window will be captured.

I was also going to suggest using "find ." as an alternative.



[ Reply to This | # ]
"I wonder if a drag-drop script could be made of "
Authored by: Barney-15 on Feb 13, '04 02:50:03PM

There is, sort of. In the Scripts folder there are Printing Scripts. One is Print Window. Another is Print Window with Subfolders.

Also, you can drag and drop a folder to a printer or the printer setup utility and it will print the listing. I don't think it is recursive, though.

---
Jim



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: hello1234 on Feb 13, '04 08:17:06PM
Here's a quick Applescript that I made. A 'choose folder' box comes up, and it asks you to pick a folder. After you do that, it creates a text file on your desktop called folder_list.txt that contains a list of the files inside of the folder that you chose. Feel free to edit it,and make it better. -Robert

tell application "Finder"
	set theFolder to choose folder "Select a Folder please"
	set theFolder to theFolder as text
	set ReplaceString to "/"
	set OldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set newText to text items of theFolder
	set AppleScript's text item delimiters to ReplaceString
	set finalText to newText as text
	set AppleScript's text item delimiters to OldDelims
	finalText
	set finalText to ("/Volumes/" & finalText)
	do shell script "ls -RF \"" & finalText & "\">~/Desktop/folder_list.txt"
end tell



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: sgi_oh_too on Feb 14, '04 02:42:09PM

just use

http://www.mit.edu/people/wsanchez/software/darwin/DropScript-0.5.dmg

i would do it for you, but i really don't have the time right now



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: sgi_oh_too on Feb 14, '04 03:26:29PM
OK OK!

I felt bad about that last post, so i wrote the damn shell script for you. Just make a plain (e.g. not a rtf) text file (Text Edit works). Paste the following code in there. Save it. Then download dropScript and drop the text file on it. Then magically, a nice droppable goodie will appear for you. have fun.


#!/bin/sh

if [ -d "$@" ]; then
  ls -RF "$@" > ~/Desktop/folder_list.txt
fi


[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: aboswell on Feb 13, '04 12:33:50PM

You could also use Fireworks or Photoshop. I don't know if the Gimp has a batch option. There is a free 30 day trial of Fireworks available. I am pretty sure that FW doesn't screw with your file structure and I do know that it makes for MUCH smaller images than iPhoto. Cool terminal hint, though.



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: readparse on Feb 13, '04 01:31:01PM
find . > out.txt


[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: b17bmbr on Feb 13, '04 11:38:46PM

try du -a. also, if you're searching for all html files, try:

du -a | grep .html

if you want to list files by size, try:

du -ah

to dump the results, just > it to files.txt



[ Reply to This | # ]
VASTLY superior solution
Authored by: SOX on Feb 14, '04 01:02:39AM

Want to have your cake and eat it too?
You can create two directories that are aliases (links) of each other. one will be the flat photoshop organization, the other will be your ma's hierarchy.

1) let mom create her tree in her pictures directory
2) open a terminal
3) find /Users/mom/Pictures | cpio -dpl /Users/mom/link_pictures
4) import link_pictures into iphoto

you should wind up with two different organizations of the same photos. These should be links of each other but not copies.



[ Reply to This | # ]
BBEdit does this
Authored by: hayne on Feb 15, '04 11:56:07AM

You can use the BBEdit text editor (even the free "Lite" version) to get a listing like the one produced by this hint. Just drag the folder from Finder onto an empty BBEdit window.



[ Reply to This | # ]
Re: BBEdit does this
Authored by: wallyfoo on Feb 15, '04 09:27:14PM

As far as I can see, they don't offer BBEdit Lite anymore. Bare Bones does offer a demo version of BBEdit, but BBEdit proper is a nearly $200 program. Fairly pricey for something you can do in the terminal, too. But my mother-in-law is behind an Army proxy filter, and it's tough for her to download anything anyway. But you're right -- BBEdit will do this too, which is great if you have BBedit.

---
_____________________________
My other sig is really witty.



[ Reply to This | # ]
BBEdit Lite is still available
Authored by: gatorparrots on Feb 16, '04 02:05:57AM
It may not be on the Bare Bones website, but it is on their FTP site: ftp://ftp.barebones.com/pub/freeware/BBEdit_Lite_612.smi.bin

[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: nghoffma on Feb 15, '04 09:04:39PM

Another tool for recursively displaying a directory structure is the freeware program tree: you can get it from fink.



[ Reply to This | # ]
Recursively print folder contents via the Terminal
Authored by: scootero1211 on Mar 19, '13 01:05:53PM

Is there a way to grep this, looking for a certain file, but including the folder it's in in the output?



[ Reply to This | # ]