Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用ls或许多其他命令,我们可以获得如下彩色结果:
ls
但是,如果这些结果太长,并且在我们将这些结果传递给less之后,颜色就会消失。
less
这是结果ls -l | less:
ls -l | less
ls | less
从手册页ls:
使用--color不带可选 WHEN 参数的选项等效于使用--color=always. 使用--color=auto时,仅当标准输出连接到终端 (tty) 时才会输出颜色代码。
使用--color不带可选 WHEN 参数的选项等效于使用--color=always.
--color
--color=always
使用--color=auto时,仅当标准输出连接到终端 (tty) 时才会输出颜色代码。
--color=auto
请注意,这always是默认设置。
always
从手册页less:
-r or --raw-control-chars 导致显示“原始”控制字符。
-r or --raw-control-chars
导致显示“原始”控制字符。
所以总的来说,你需要这个:
ls -l --color | less -r