How to list all text files in a directory?

Directory listing in OSX output to text file.

  • 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.

  • Answer:

    1. open up a console 2. type ls -l > list.txt find the txt and you're done. The -l is optional.

Jack Karaoke at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

An easy GUI solution is to download the free version of http://www.barebones.com/products/textwrangler/index.shtml from Bare Bones Software. Simply drag a folder on to an open document and it will list all folders and nested documents within.

captainscared

type 'man ls' for more options, also.

angry modem

d'oh.. just like the recent askme where someone said "borrowed from unix". thanks

Jack Karaoke

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

mzurer

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.

grouse

Of course I have only tested that on other UNIXes, I'm just guessing that it should work on Mac OS X.

grouse

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 http://cfv.sourceforge.net/. 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.

Freaky

*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.

Freaky

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.

ldenneau

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.