问题描述
我对 Linux(在这种情况下为 CentOS)相当陌生.我有一个文件夹,里面有大约 2000 个文件.理想情况下,我想在命令提示符处执行一个命令,将所有文件的名称写到一个 txt 文件中.
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.
推荐答案
你可以使用
ls > filenames.txt
(通常,使用Terminal"、shell"或Bash"启动 shell.)您可能需要先使用 cd
进入该文件夹,或者您可以 ls ~/docs >文件名.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
这篇关于如何将文件夹中的文件列表发送到Linux中的txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!