Useful journald tweaks

Flush old logs in journalctl

By date or by size:

    sudo journalctl --vacuum-time=2d
    sudo journalctl --vacuum-size=500M

Tail journalctl

journalctl -f

For a specific service:

journalctl -u httpd -f

Store logs on disk

(from http://unix.stackexchange.com/questions/159221/how-display-log-messages-from-previous-boots-under-centos-7)

On CentOS 7, you have to enable the persistent storage of log messages:

# mkdir /var/log/journal
# systemd-tmpfiles --create --prefix /var/log/journal
# systemctl restart systemd-journald

Otherwise, the journal log messages are not retained between boots. This is the default on Fedora 19+.

Useful RPM/YUM commands

Sort RPMs by size

rpm -qa --queryformat '%{size} %{name}\n' | sort -rn | more

Extract rpm into current folder instead of installing:

rpm2cpio boost-system-1.53.0-23.el7.x86_64.rpm | cpio -idmv

Trace a binary or file to the RPM that installed it:

yum whatprovides /usr/lib64/libdbus-c++-1.so.0

or this:

rpm -qf /usr/lib64/libdbus-c++-1.so.0

Yum/dnf revert

If a yum remove wiped out several packages, do this:

  • dnf history # note the id of the bad removal here
  • dnf history undo 96

yum/dnf will reinstall all the packages that were removed in that id.

Dependencies of a package

This command shows what other packages need the queried package:

repoquery --whatrequires libunwind

Another way, without using repoquery:

rpm -q --whatrequires python-ipaddress

This command shows what other packages need to be installed for a queried package:

yum deplist nginx