我正在使用 ls -a
命令来获取目录中的文件名,但输出在一行中。
像这样:
. .. .bash_history .ssh updater_error_log.txt
我需要一个内置的替代方法来获取文件名,每个文件名都在一个新行上,如下所示:
.
..
.bash_history
.ssh
updater_error_log.txt
最佳答案
使用 -1
选项(注意这是“一个”数字,而不是小写字母“L”),如下所示:
ls -1a
不过,首先,请确保您的 ls
支持 -1
。 GNU coreutils(安装在标准 Linux 系统上)和 Solaris 可以;但如果有疑问,请使用 man ls
或 ls --help
或查看文档。例如:
$ man ls
...
-1 list one file per line. Avoid '\n' with -q or -b
https://stackoverflow.com/questions/3886295/