ssh 会话中的自动换行不适用于 grep

use*_*029 2 linux ssh grep

当我通过 ssh 连接到我的 Linux 服务器并像这样使用 grep 时:

grep '超时超时' 日志文件 | 较少的

自动换行不起作用。

但是,如果我使用相同的命令但先使用 less,如下所示:

更少的日志文件| grep '超时'

线条环绕。我不确定是什么问题,或者这是否正常。但无论我使用什么 ssh 客户端,它都会发生。我已经尝试过 putty 和 Ubuntu 客户端。我怎样才能解决这个问题?

Mic*_*ton 5

这不是 的默认行为less。默认是换行。

您看到这种行为是因为您-SLESS环境变量中设置了选项(和其他几个)。

       -S or --chop-long-lines
              Causes  lines  longer than the screen width to be chopped (trun?
              cated) rather than wrapped.  That is, the portion of a long line
              that does not fit in the screen width is not shown.  The default
              is to wrap long lines; that is, display  the  remainder  on  the
              next line.
Run Code Online (Sandbox Code Playgroud)

要解决此问题,请检查您的 shell 启动脚本(例如$HOME/.bash_profile, $HOME/.bashrc)和系统 shell 启动脚本(例如/etc/profile.d目录中的脚本)以查看设置环境变量的位置,并进行所需的更改。