Save a List of Files & Folder Contents Into a Text File

Oct 11, 2012 - 3 Comments

A directory listing saved as a text file

Saving a complete listing of files contained with a folder is easy, and there are two quick ways to save that list as a text file.

Save a List of Files from Finder

The first approach may be easiest for most users and is done through the OS X Finder and TextEdit app, it’s a simple matter of copying and pasting:

  • Open the folder you want to get a content listing of and hit Command+A (Select All) followed by Command+C (Copy)
  • Now launch TextEdit and pull down the “Edit” menu and select “Paste and Match Style”, or hit Command+Option+Shift+V
  • Save the directory listing as either a .txt or .rtf

Save a list of files into a text document

Saving a Detailed List of Files from Terminal

The second approach uses the command line, and despite being done through Terminal is not much more complicated than the copy & paste approach outlined above. Launch Terminal from /Applications/Utilities/ to get started.

At it’s most basic, the command is as follows:

ls > contents.txt

Including hidden files in the list requires the -a flag:

ls -a > allcontents.txt

To dump the contents of a specific folder, specify the directory path as follows:

ls /Library/Preferences/ > LibPrefsList.txt

Attaching certain flags to the ls command will allow the list to reveal more than just a file content list, the -l flag will also list permissions, file ownership, and modification dates:

ls -la /Library/Preferences/ > detailedprefsinfo.txt

Because the ls command accepts flags that detail additional attributes of files and folders, it can be much more informative than the Finder & TextEdit approach, which does not display details like file ownership or document permissions.

The command line approach also lets you do things like compare two directory listings by using the diff command, that can either be done by comparing the output files against each other, or even directly comparing the folders and saving difference those results as a text file.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. h00jmiwoko says:

    This looks like advanced hacker stuff! Will it break my Mac?

  2. Troy says:

    What flag do you use with the ls command to arrange by file type?

  3. Ali Jose says:

    gr8!! thanks it helped me save a lot of time at my work

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates