如何获取不同行中的文件名列表
我想获取目录中所有文件的列表,就像使用 ls 一样,以便每个文件名都位于单独的行上,而不需要 ls -l 提供的额外详细信息代码>.我查看了ls --help
并没有找到解决方案。我尝试这样做
ls -l | cut --fields=9 -d" "
,但 ls 不使用列之间固定数量的空格。关于如何做到这一点的任何想法,最好是在一行中?
I want to get a list of all the files in a directory, like with ls
, so that each filename will be on a seperate line, without the extra details supplied by ls -l
. I looked at ls --help
and didn't find a solution. I tried doing
ls -l | cut --fields=9 -d" "
but ls
doesn't use a fixed number of spaces between columns. Any idea on how to do this, preferably in one line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
ls -1
这是一个数字,不是小
L
。ls -1
That is a number, not small
L
.ls -1
。来自帮助:适用于 cygwin 和 FreeBSD,因此它可能不太特定于 GNU。
ls -1
. From the help:Works on cygwin and FreeBSD, so it's probably not too GNU-specific.
没有管道的解决方案:-)
请注意,长选项仅在 GNU coreutils 其中 BSD ls 仅支持短参数
-1
solution without pipe-ing :-)
Note that the long options are only supported on the GNU coreutils where BSD ls only supports the short arguments
-1
也许:
Perhaps:
ls |猫
...
或者可能是
ls -1
ls | cat
...
or possibly,
ls -1
使用 sed 命令列出单列
Use sed command to list single columns
试试这个:
这里
num
是您要列出的列数。Try this:
Here
num
is number of columns you want to list in.首先你可以使用这个。它将每行显示一个文件。
ls -l | sed 's/(.* )(.*)$/\2/'
或者您可以使用
find 。 -最大深度1 | sed 's/.///'
两者都是相同的。
first you can use this. it will display the one file per line.
ls -l | sed 's/(.* )(.*)$/\2/'
or else you can use thus
find . -maxdepth 1 | sed 's/.///'
both the things are the same.
这也有效:echo -e "\n$(ls)"
This is also working: echo -e "\n$(ls)"
这也将做
This will also do