大网数据广告活动
服务器运维问答

journalctl - stop following without exiting pager

· 52CE 我爱测

If I do: journalctl -u my-service then a Shift-F to follow while paging, how do I (interrupt to abort) without exiting the pager? With less , I typically just ^C , but if I do that in journalctl, it exits the entire pager.

问题原文

原帖链接 · MikeKusold · CC BY-SA 3.0

If I do:

journalctl -u my-service

then a Shift-F to follow while paging, how do I (interrupt to abort) without exiting the pager?

With less, I typically just ^C, but if I do that in journalctl, it exits the entire pager.

社区高分解答

原帖链接 · Mark Stosberg · CC BY-SA 3.0

You are using less at that point, but ^C is behaving differently due to how it was invoked by journalctl. The flags that journalctl passes to less include the following defaults:

 FRSXMK

Of these, I think the "K" option applies here:

-K or --quit-on-intr Causes less to exit immediately (with status 2) when an interrupt character (usually ^C) is typed. Normally, an interrupt character causes less to stop whatever it is doing and return to its command prompt. Note that use of this option makes it impossible to return to the command prompt from the "F" command.

So, setting $SYSTEMD_LESS in your environment and omitting the "K" option should resolve the issue, it didn't work on my test on Ubuntu 16.04:

 SYSTEMD_LESS="FRSXM"journalctl -u nginx

However, you can get the behavior you want confirm that the K flag is related by comparing the behavior of the following variations:

# ^C after Shift-F does not completely quit
journalctl -u nginx | less -FRSXM

# ^C after Shift-F completely quits
journalctl -u nginx | less -FRSXMK

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。