Watch Live Log

To show real-time logs in the Ubuntu terminal using the command line interface (CLI), you can use several tools and commands. Here are the most common ones:

1. Using tail command

The tail command allows you to view the end of a file, and with the -f option, you can follow the file as it gets updated in real time.

Command:

tail -f /path/to/logfile

For example, to view system logs:

tail -f /var/log/syslog

This will show the latest lines of the syslog file and continue to display new log entries as they are written to it.

Option to follow multiple files:

tail -f /path/to/logfile1 /path/to/logfile2

2. Using journalctl for Systemd Logs

If your system uses systemd (which is common on modern Ubuntu versions), you can use journalctl to view logs from various services.

Command:

journalctl -f

This will display the most recent logs and continue to follow the new logs in real time.

To view logs of a specific service:

journalctl -f -u service_name

For example, to follow the logs for the apache2 service:

journalctl -f -u apache2

Show logs since boot:

journalctl -f --since "today"

3. Using less with +F

If you prefer using less (a pager program) to view logs, you can use the +F option to follow logs in real time.

Command:

less +F /path/to/logfile

It will behave like tail -f, but you’ll be able to scroll up and down within the log file if needed.

4. Using multitail (if installed)

multitail allows you to view multiple log files at once in real time.

Command:

multitail /path/to/logfile1 /path/to/logfile2

To install multitail, you can run:

sudo apt install multitail

5. Using watch to Monitor a Command

If you need to watch the output of a specific command in real time, you can use watch. This is useful if you want to see output like df (disk usage), free (memory usage), or other commands on a recurring basis.

Command:

watch -n 1 'command'

For example:

watch -n 1 'df -h'

This will update every second (-n 1), showing the output of df -h.


These methods allow you to follow and monitor logs or command outputs in real time from your terminal in Ubuntu.

Related
Ubuntu · Tips