如何获取不同行中的文件名列表

发布于 2024-10-19 21:23:39 字数 225 浏览 11 评论 0原文

我想获取目录中所有文件的列表,就像使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

各自安好 2024-10-26 21:23:39

ls -1

这是一个数字,不是小L

ls -1

That is a number, not small L.

浮萍、无处依 2024-10-26 21:23:39

ls -1。来自帮助:

-1 每行列出一个文件

适用于 cygwin 和 FreeBSD,因此它可能不太特定于 GNU。

ls -1. From the help:

-1 list one file per line

Works on cygwin and FreeBSD, so it's probably not too GNU-specific.

江挽川 2024-10-26 21:23:39

没有管道的解决方案:-)

 ls --format single-column

请注意,长选项仅在 GNU coreutils 其中 BSD ls 仅支持短参数 -1

solution without pipe-ing :-)

 ls --format single-column

Note that the long options are only supported on the GNU coreutils where BSD ls only supports the short arguments -1

左秋 2024-10-26 21:23:39

也许:

ls | awk '{print $NF}'

Perhaps:

ls | awk '{print $NF}'
泪眸﹌ 2024-10-26 21:23:39

ls |猫
...
或者可能是ls -1

ls | cat
...
or possibly, ls -1

流年已逝 2024-10-26 21:23:39

使用 sed 命令列出单列

ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'

Use sed command to list single columns

ls -l | sed 's/\(^[^0-9].\*[0-9]\*:[0-9]\*\) \(.*\)/\2/'
束缚m 2024-10-26 21:23:39

试试这个:

$ ls | xargs -n num

这里 num 是您要列出的列数。

Try this:

$ ls | xargs -n num

Here num is number of columns you want to list in.

我要还你自由 2024-10-26 21:23:39

首先你可以使用这个。它将每行显示一个文件。

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.

梦纸 2024-10-26 21:23:39

这也有效:echo -e "\n$(ls)"

This is also working: echo -e "\n$(ls)"

季末如歌 2024-10-26 21:23:39

这也将做

ls -l | awk '{print $NF}'

This will also do

ls -l | awk '{print $NF}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文