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.
what does the terminal string look like if I am trying to make a list of everything (folders and contents) on an external drive? I keep getting “No such file or directory” error – thanks
How can I get a list of subfolders and their files. I’d like a list of all files including subfolder names and the files they contain.
ls -R folder/path > text_file_name.txt
I have a folder with a content of 25401 files (images) – of course the copy/paste method would completely destroy my machine with a size of ~8 MB per file.
Splitting the folder is (unfortunately) not an option.
Any idea how to generate a list of names from this giant?
I’d say try the command line approach:
First in Terminal change to the directory path:
Then use ls with redirection to a text file containing the listings file names:
ls > FolderContents.txt
THANK YOU , THANK YOU THANK YOU!!!!!!!
I figured out the copy/paste method on my own, but have been looking for the detailed info method for YEARS!
I have never used Terminal, but was easily able to create the file and then customize the command line in just minutes following your explanation and steps. Well done!
Now I’m thirsting to learn more so I can make the line do exactly what I want and use what I get.
Where do I go to learn, for example:
what are the other file characteristics being written by ls -la along with file/folder name and mod date?
how can I write to a tab delimited file or csv that will open parsed into columns by Numbers?
Can I drill down to subfolders with one command?
Whether you have time to answer, I still say THANK YOU!
Janet, yes you can do all of that in the command line of Mac. We have hundreds of articles on various command line topics you can review here:
Including drilling down subfolders, getting more info, redirecting output to text files, etc, the archives go back many years. Enjoy!
ls -lh -R > listofsizes.txt
Copy / paste method does not work.
It does work.
The copy/paste method for listing files works fine.
Be sure you paste the list into a file that is plain text format, like in TextEdit, BBEdit, TextWrangler, etc. If it is not plain text it will attempt rich text pasting with the documents instead.
Few years late on this question, but couldn’t hurt – can I use this method or a similar method to get info on file sizes for a large batch of folders? I’m talking over 300.
ls -lh /path/to/folder/ > listofsizes.txt
Thank u very much!
gr8!! thanks it helped me save a lot of time at my work
What flag do you use with the ls command to arrange by file type?
This looks like advanced hacker stuff! Will it break my Mac?