Systemctl status always shows full log, even with --lines

5,536

Solution 1

The command systemctl status display the status of the service and the corresponding lines from journalctl, the --lines=3 will limit the displayed number of lines from the journal to 3. e,g:

systemctl --user status resilio-sync --lines=0

will display only the status of esilio-sync service without the journalctl log.

-n, --lines=

When used with status, controls the number of journal lines to show, counting from the most recent ones. Takes a positive integer argument, or 0 to disable journal output. Defaults to 10.

To limit the output of the systemctl status command you can use options:

systemctl check resilio-sync
systemctl is-active resilio-sync
systemctl is-enabled resilio-sync

or by groupping the options:

systemctl is-active is-enabled resilio-sync

Solution 2

This is what the head command was designed for.

systemctl --user status resilio-sync | head -n 3
Share:
5,536

Related videos on Youtube

Bauglir42
Author by

Bauglir42

Updated on September 18, 2022

Comments

  • Bauglir42
    Bauglir42 over 1 year

    I'm trying to get the status of a unit, but only the first 3 lines like this:

    systemctl --user status resilio-sync --lines=3
    

    I've tried various variations of this with -n 3 etc..., nothing works. And the strange part: it always shows the full log (13 lines), instead of 10 lines which should be the default according to the documentation for systemctl.

    Trying systemctl status confirms this: it just outputs all 45 lines to the terminal, when it actually should be 10.

    Am I missing something here? As far as I know I didn't change anything.

    As a workaround I'm currently using:

    systemctl --user status resilio-sync | sed -ne '1,3p'
    

    but I'd rather like to fix the underlying problem and use the native command. System is Kali Linux (re4son-kernel, sticky fingers) on a Raspberry Pi (easy to blame on this strange setup, but since this is core Linux functionality I don't think it should matter)

    Output of the first command

    • Admin
      Admin over 5 years
      Welcome , Please add the output of the first command.
    • Admin
      Admin over 5 years
      added it as a picture as I don't have the other machine connected to the internet atm.
  • Bauglir42
    Bauglir42 over 5 years
    ohhh the --lines argument only affects the journal part. I misunderstood the doc in that regard. Allright, that explains it, seems like I have to use head or sed