你能按名称对 ls 列表进行排序吗?
你能按名称对 ls 列表进行排序吗?
ls -v
命令。-v natural sort of (version) numbers within text
ls -vd1 */
将按顺序仅显示文件夹。它似乎依赖于ASCII值,因此您将看到大写字母始终优先于小写字母。这是因为大写字母始终具有较低的ASCII值。In Debian Jessie, this works nice:
ls -lah --group-directories-first
# l=use a long listing format
# a=do not ignore entries starting with .
# h=human readable
# --group-directories-first=(obvious)
# Note: add -r for reverse alpha
# You might consider using lh by appending to ~/.bashrc as the alias:
~$ echo "alias lh='ls -lah --group-directories-first'" >>~/.bashrc
# -- restart your terminal before using lh command --
ls | sort -V
如果您有编号的文件,例如
,它将很好地排序。File-8.webvtt
File-9.webvtt
File-10.webvtt
File-11.webvtt
ls
命令不带任何选项已经按名称排序,-h
选项只是以“人类可读”的形式打印大小等信息。 - Michael