制作“ ls”命令排序“ a”;在“ B”之前(vs a-> b-> A-> B) [英] Making the "ls" command sort "a" before "B" (vs a->b->A->B)

查看:71
本文介绍了制作“ ls”命令排序“ a”;在“ B”之前(vs a-> b-> A-> B)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种以不区分大小写的方式打印ls命令的结果的方法。

I am trying to find a way to have the results of an ls command be printed in a case insensitive manner.

当前执行ls命令会导致:

currently an ls command results in:

Apple
Boy
Chart
Dock
apples
boys
charts
docks

我想要的是什么

Apple
apples
Boy
boys
Chart
charts
Dock
docks

可能吗?

推荐答案

ls (至少在使用GNU coreutils版本的情况下; ls --version 进行检查)会根据当前语言环境对文件名进行排序。

ls (at least if you're using the GNU coreutils version; ls --version to check that) sorts file names according to the current locale.

可用的语言环境集因系统而异(列表中为 locale -a ),但在我的系统上为:

The set of available locales varies from system to system (locale -a for a list), but on my system this:

LC_COLLATE=en_US.utf8 ls

b a A 的名称进行排序>和 B -尽管可能与您要查找的顺序不完全

sorts names with a and A before b and B -- though it might not be exactly in the order you're looking for.

这有效即使 ls 在多列中列出文件,使用 sort -f 也很难做到。

This works even when ls lists files in multiple columns, something that's difficult to do with sort -f.

(我专门将 $ LC_COLLATE 设置为 C ,以便对语言环境敏感排序以ASCII顺序完成。)

(I have $LC_COLLATE set to C specifically so that locale-sensitive sorting is done in ASCII order.)

这篇关于制作“ ls”命令排序“ a”;在“ B”之前(vs a-> b-> A-> B)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆