Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send list of file in a folder to a txt file in Linux

I'm fairly new to Linux (CentOS in this case). I have a folder with about 2000 files in it. I'd like to ideally execute a command at the command prompt that would write out the name of all the files into a single txt file.

If I have to, I could write an actual program to do it too, I was just thinking there might be a way to simply do it from the command prompt.

like image 846
alchemical Avatar asked Nov 06 '10 06:11

alchemical


People also ask

How do I export a list of files from a folder to text?

Right-click that folder and select Show more options. Click Copy File List to Clipboard on the classic menu. You'll still need to paste the copied list into a text file.

How do you send listing of files to a file in Unix?

The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default. You can choose the ls (no details) or ls -l (lots of details) to determine your view.


1 Answers

you can just use

ls > filenames.txt 

(usually, start a shell by using "Terminal", or "shell", or "Bash".) You may need to use cd to go to that folder first, or you can ls ~/docs > filenames.txt

like image 115
nonopolarity Avatar answered Sep 19 '22 16:09

nonopolarity