Save a List of Files & Folder Contents Into 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
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.