Directory listing in OSX output to text file.
August 20, 2005 4:39 PM   Subscribe

How to list the contents of an OSX directory, and output to text file?

I run Windows, but have a couple gigs of data on a Mac. I burned DVDs of the data and brought them home to my PC. I want to email the Mac owner a command line that produces a text file listing of the directory contents that he can then email back to me, just to make sure I got everything.

I imagine this is quite simple under OSX, but I nee to send him simple directions.

The directory in question has about 8 sub directories, all filled with .wav files, all with unique titles.
posted by Jack Karaoke to Computers & Internet (15 answers total) 2 users marked this as a favorite
Best answer: 1. open up a console
2. type ls -l > list.txt

find the txt and you're done. The -l is optional.
posted by angry modem at 4:49 PM on August 20, 2005

type 'man ls' for more options, also.
posted by angry modem at 4:49 PM on August 20, 2005

Response by poster: d'oh.. just like the recent askme where someone said "borrowed from unix".

posted by Jack Karaoke at 4:53 PM on August 20, 2005

Best answer: add -R if you want to descend into the subdirectories...

I would do it this way:

Open a Finder window. Click the DVD. Select all in the right hand side.

ls -l -R [at this point drag the folders from the right-hand Finder window into the terminal] > ~/Desktop/DVDlist.txt
posted by mzurer at 4:56 PM on August 20, 2005

If you really want to make sure the data was copied correctly, do something like:

find . -type f -print0 | xargs -0 md5sum > ~/Desktop/DVDlist.txt

which will get you an MD5 hash of every file in the current directory and its subdirectories. You can then use the diff command to compare the two text files.
posted by grouse at 5:27 PM on August 20, 2005

Of course I have only tested that on other UNIXes, I'm just guessing that it should work on Mac OS X.
posted by grouse at 5:27 PM on August 20, 2005

If you want to make sure the files are identical, you can ask them to do:

cd /path/to/dir
find -print0 . |xargs -0 md5 >list.txt

This will generate md5's for each file, which you can then compare with your copies using something like cfv.

Explanation: cd changes the current working directory. "find -print0 ." produces a recursive file listing from the current directory using NULL to seperate them, xargs takes the list and passes it to md5, respecting limits on argument lengths and seperating them properly. -print0 and -0 are optional but recommended if you have any potentially odd filenames.
posted by Freaky at 5:32 PM on August 20, 2005

*shakes fist at grouse*

I would have expected OS X to have the BSD md5(1) rather than the Linuxy md5sum(1) though. Depending on how old the userspace is in OS X sha1(1) may also be usable, if you want to make the probability of errors even more insanely tiny.
posted by Freaky at 5:36 PM on August 20, 2005

One short addition to angry modem's instructions:

3. Type "open list.txt". You don't need to bother with finding the file; just tell OS X to open it.
posted by ldenneau at 5:49 PM on August 20, 2005

OSX does have md5 instead of md5sum; this causes no end of tab-completion confusion when one uses both OSX and Linux daily :) And there's no sha1.
posted by cyrusdogstar at 5:55 PM on August 20, 2005

Also, the directory is the first argument to find, pace Freaky's example.
posted by kenko at 6:17 PM on August 20, 2005

Yup, good catch kenko. 32 hour waking binges and arcane Unix commands don't mix well.
posted by Freaky at 7:38 PM on August 20, 2005

md5sum can be aquired easily through installation of fink.
posted by joeblough at 10:00 PM on August 20, 2005

An easy GUI solution is to download the free version of TextWrangler from Bare Bones Software. Simply drag a folder on to an open document and it will list all folders and nested documents within.
posted by captainscared at 8:41 AM on August 21, 2005 [1 favorite]

Why make someone do this on the command line? Have them open the finder, press cmd-A to select all, cmd-C to copy it to the clipboard.

Then have them open an email to you and press cmd-V to paste the file info into the message body.

I feel sorry for you Windows people. You have no concept of how a computer is supposed to behave.
posted by ikkyu2 at 8:32 PM on August 21, 2005

« Older Nintendo DS for a three year old?   |   Wire fence problem Newer »
This thread is closed to new comments.