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

标签 bash pipe terminal-emulator

使用 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/

相关文章:

vim - 带有类似 vim 的命令的终端仿真器或 shell

shell - 适用于 Windows 10 的 Neovim 终端模拟器配置

php - Heroku 403 Forbidden - Laravel 5

bash - 如何创建一个可以通过位置参数和命名参数接受信息的通用 Bash 函数

unix - 匹配 sed 命令中的特定行

unix - 将 unix 管道重新连接到子进程

mysql - 通过多个文件导入填充 MySQL 表

bash - 将多个参数传递给 UNIX shell 脚本

c - C 中子进程之间的 exec() 和 pipe()

android - 构建 Android 终端模拟器