当我SSH我的Linux服务器,并像这样使用grep:
grep'timeout exceeded'logfile | 减
自动换行不起作用。
但是,如果我使用相同的命令,但首先使用较less,如下所示:
less日志文件| grep超时超时
线条包裹。 我不确定问题是什么,或者这是否正常。 但是,不pipe我使用的ssh客户端如何。 我已经尝试了腻子和Ubuntu客户端。 我怎样才能解决这个问题?
当你这样做
grep 'timeout exceeded' logfile | less
您可以使用右箭头键移动到行的末尾(向左移动)。
这不是默认的行为。 默认情况下是换行较长的行。
您看到了这种行为,因为您在LESS环境variables中设置了-S选项(以及其他几个选项)。
-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.
要解决这个问题,请检查你的shell启动脚本(例如$HOME/.bash_profile , $HOME/.bashrc )和系统shell启动脚本(例如/etc/profile.d目录下的启动脚本)来查看环境variables的位置正在设置,并进行所需的更改。
如果你less是默认不包装线,尝试使用完整的pathless。 运行一下,看看它给你什么path。 然后使用该path。 例如,如果它位于/ usr / bin / less那么请尝试grep 'timeout exceeded' logfile | /usr/bin/less grep 'timeout exceeded' logfile | /usr/bin/less 。