gpt4 book ai didi

bash - 如何制作 ls |不那么丰富多彩?

转载 作者:行者123 更新时间:2023-11-29 09:12:06 25 4
gpt4 key购买 nike

使用 ls 或许多其他命令,我们可以获得像这样的彩色结果:

enter image description here

但如果这些结果太长,并且在我们将这些结果通过管道传输到 less 之后,颜色就会消失。

这是 ls -l | 的结果少:

enter image description here

  1. 为什么颜色消失了。
  2. 如何生成 ls | 的结果少多彩?

最佳答案

来自man page for ls :

Using the --color option without the optional WHEN argument is equivalent to using --color=always.

With --color=auto, color codes are output only if standard output is connected to a terminal (tty).

请注意,always 是默认值。

来自man page for less :

-r or --raw-control-chars

Causes "raw" control characters to be displayed.

总的来说,你需要这个:

ls -l --color | less -r

关于bash - 如何制作 ls |不那么丰富多彩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com