A powerful debugging tool.

Share this link

Most system administrators know the tail command. By default, it displays the 10 last lines of a file.

The -f option is less known. Besides displaying the last 10 lines of a file, it mainly provides a way to watch what is written into a file in real-time:

# tail -f /var/log/messages
Apr  4 20:30:01 vm systemd: Stopping user-0.slice.
Apr  4 20:31:35 vm systemd: Created slice user-0.slice.
Apr  4 20:31:35 vm systemd: Starting user-0.slice.
Apr  4 20:31:35 vm systemd: Started Session 961 of user root.
Apr  4 20:31:35 vm systemd-logind: New session 961 of user root.
Apr  4 20:31:35 vm systemd: Starting Session 961 of user root.
Apr  4 20:31:35 vm dbus[590]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Apr  4 20:31:35 vm dbus-daemon: dbus[590]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Apr  4 20:31:35 vm dbus[590]: [system] Successfully activated service 'org.freedesktop.problems'
Apr  4 20:31:35 vm dbus-daemon: dbus[590]: [system] Successfully activated service 'org.freedesktop.problems'
Apr  4 20:33:53 vm systemd: Started Session 962 of user root.
Apr  4 20:33:53 vm systemd-logind: New session 962 of user root.
Apr  4 20:33:53 vm systemd: Starting Session 962 of user root.
...

When debugging complicated situations involving several files, the tail command proves to be a invaluable tool. In fact, you can specify several files after the -f option and a header will be displayed each time something is written into a different file:

# tail -f /var/log/messages /var/log/secure
==> /var/log/messages <== 
Apr 4 20:51:07 vm systemd-logind: Removed session 963. 

==> /var/log/secure <== 
Apr 4 20:51:11 vm sshd[21933]: Accepted password for root from 94.23.44.29 port 47411 ssh2 

==> /var/log/messages <== 
Apr 4 20:51:11 vm systemd: Started Session 966 of user root. 
Apr 4 20:51:11 vm systemd-logind: New session 966 of user root. 

==> /var/log/secure <== 
Apr 4 20:51:11 vm sshd[21933]: pam_unix(sshd:session): session opened for user root by (uid=0)

==> /var/log/messages <==
Apr 4 20:51:11 vm systemd: Starting Session 966 of user root.

...

For example, OpenStack engineers use this kind of command to debug their configuration on compute nodes:

# tail -f /var/log/{ceilometer,neutron,nova,openvswitch}/*.log /var/log/syslog

When troubleshooting, using the tail command should become a reflex!

Posted in RHEL7
3 comments on “A powerful debugging tool.
  1. hunter86_bg says:

    Wow, that was interesting. I’ve never imagined that tail -f takes as argument more than 1 log.

  2. shmsohel says:

    Really interesting !!!

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 10 minutes.
Create two new user accounts "steve" and "oliver".
Create a group "team". Create a directory "shared".
All files put into the "shared" directory by "steve" or "oliver" should belong to the "team" group and be only visible by them.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a default secure MariaDB database called maria with a user named muser with all privileges.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...