155

How can I keep long strings from truncating in terminal? For example if I run

journalctl -xn

There's a lot of text that I cannot read. I am open to using other programs/tools.

1
  • 26
    Who came up with the idea to truncate the output anyways?
    – j4hangir
    Commented Dec 2, 2020 at 20:09

8 Answers 8

173

From the journalctl manpage:

   The output is paged through less by default, and long lines are
   "truncated" to screen width. The hidden part can be viewed by using the
   left-arrow and right-arrow keys. Paging can be disabled; see the
   --no-pager option and the "Environment" section below.

If you don't want to constantly be using the left and right arrow keys, simply pipe it directly to less:

$ journalctl -xn | less

This will wrap lines that are too long for your terminal (the default behavior of less, which journalctl overrides).

Or, of course, if you don't mind possibly having to use your terminal's scrollback, you could use no pager at all:

$ journalctl -xn --no-pager
8
  • 13
    This is really frustrating. If pager is set to less, and LESS does not include -S, journalctl should not be applying -S to the invocation of less!! That is, setting PAGER=less and LESS=$x (where $x is any string that does not contain S) should give the desired behavior. Commented Nov 11, 2018 at 13:19
  • 5
    That is, journalctl should honor LESS, and the user should not have to also set SYSTEMD_LESS! (Apologies, doorknob, this is a bit of a rant that probably doesn't belong as a comment to your answer) Commented Nov 11, 2018 at 13:21
  • Silly William. Mr. Pottering knows what's best for you, and if you don't like it, you are obviously wrong.</rant>
    – dannysauer
    Commented Oct 1, 2019 at 17:21
  • 3
    For colored output: SYSTEMD_PAGER="less -r" journalctl -xn
    – V02460
    Commented Mar 28, 2020 at 10:26
  • 2
    @PabloA Prefixing SYSTEMD_COLORS=true helps.
    – V02460
    Commented Jul 18, 2021 at 23:31
32

I also do:

journalctl -xn | less

But you can also set the SYSTEMD_LESS environment variable:

SYSTEMD_LESS=FRXMK journalctl -xn
# Or even
# SYSTEMD_LESS="" journalctl -xn
# The environment variable needs to be there, but can be the empty string

I got that from: [systemd-devel] [PATCH] pager: wrap long lines by default

Set it in your .bashrc and be done with it! :-)

That systemd needs to setup less specially and doesn't just honor the less defaults and the LESS environment seems a little arrogant to me, but hey, this works...

6
  • SYSTEMD_LESS support is only recently added, e.g CentOS 7 does not have a version that supports it
    – jnas
    Commented Nov 19, 2015 at 9:02
  • Works at least on CentOS 7.5.
    – Vertigo
    Commented Aug 14, 2018 at 11:28
  • 2
    Great solution, I also added Defaults env_keep += "LESS SYSTEMD_LESS" to /etc/sudoers. It's for those times when I accidentally put sudo in front of e.g. systemctl status. Commented Sep 14, 2018 at 17:51
  • 2
    It's not merely "a little arrogant", it's incredibly annoying. I hope it's not arrogance, but ignorance that drives this behavior. Commented Nov 11, 2018 at 13:22
  • 2
9

If the program already uses less (if not, pipe the output to it), you can enable/disable line wrapping by typing -S (in less), This works for other less options as well.

6

Note also that:

journalctl -f

will show you all the latest as it comes in and wrap like any normal human being (or even sysadmin) would expect to allow easy reading, copy-pasting, and everything else.

2

This is the command I use for CentOS 7, which preserves coloring and wraps lines:

SYSTEMD_PAGER="less -r"  journalctl
2

$ SYSTEMD_PAGER="less +-S" journalctl

+ executes command on start and -S disable chopping.

You can also set this value for a session or save in rc/profile script.

0

I type in terminal,
journalctl | more, works great for me then I use arrows up or down.

0

The problem arises because journalctl's default for $SYSTEMD_LESS is "FRSXMK" (from the manpage), and less's -S "Causes lines longer than the screen width to be chopped (truncated) rather than wrapped."

The simplest way to achieve what you want is to use the --no-pager option. But if you pipe the output to a pager like less or more anyway, even this isn't necessary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .