简体   繁体   English

如何命令ls命令按数字顺序显示?

[英]How to order ls command display in numerical order?

I created 3 files in a directory with the following names:我在一个目录中创建了 3 个文件,名称如下:

11 13 9

Problem, as I created file 9 after 13 it is placed after file 13 when I do the ls command.问题,因为我在13之后创建了文件9 ,当我执行ls命令时,它被放置在文件13之后。

Do you have any idea to make the ls command sort the files in the numerical order, like this:你有什么想法让ls命令按数字顺序对文件进行排序,像这样:

9 11 13

Look at the man page for ls . 查看lsman页。 From there- 从那里-

-v natural sort of (version) numbers within text. -v文本中的自然类型(版本)数字。

You'll find that the command ls -v does what you want. 你会发现命令ls -v可以做你想要的。

If you want the file names on different lines then you can do ls -1v . 如果你想在不同的行上的文件名,那么你可以做ls -1v

list with lines without columns:没有列的行列表:

ls -x

Using tr to avoid multiple lines output:使用 tr 避免多行输出:

ls | tr "\n" " "

and to ensure to accurately force ascending order:并确保准确强制升序:

ls -v | tr "\n" " "

some useful and essential information from linux.org about ls来自linux.org 的一些关于 ls 的有用和基本信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM