开发者

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

开发者 https://www.devze.com 2023-01-23 14:29 出处:网络
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

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.


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


If only names of regular files immediately contained within a directory (assume it's ~/dirs) are needed, you can do

find ~/docs -type f -maxdepth 1 > filenames.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消