DevOps Debugging Part 5: less

Neeran Gul
3 min readNov 18, 2022
Photo by Damian Patkowski on Unsplash

This is a multi-part series where we will explore essential unix commands for debugging applications. These skills are critical when an outage occurs or something doesn’t work as expected. This is aimed at DevOps Engineers, SREs and linux sysadmins. Below is a quick navigation if you want to jump to the other parts.

  1. netcat
  2. curl
  3. dig
  4. ps
  5. less
  6. df & du
  7. openssl
  8. lsof
  9. netstat
  10. iostat

In this part we are going to cover less . This command is a way of displaying the contents of a file without locking it. Essentially it is a cat that has the ability to scroll up and down and find text. Now why is this important during debugging? Let’s have a look at how it is used. Keep in mind that we will not cover the whole usage of the command and what fancy things it can do but rather how to use the command to debug servers and applications.

Installation

To install network on redhat/centos/ubuntu/osx run:

# redhat/centos/amazon linux
$ yum install less
# ubuntu
$ apt-get install less
# OSX/Mac (usually already installed)# test for installation
$ less --help

If you get a command not found back then please reach out below in the comments section.

Usage

See the contents of a file without locking it.

$ less /var/log/syslog

We can use d to go pages down, u to go page up, G to go to end, / then search for what you are looking for, for example /ERROR, then press n to find the next occurrence and shift-n to find previous occurrence. Press shift-f to tail the file.

Debugging

During an outage less can be great to find issues that are transient or only show up sometimes that cause unavailability. less is perfect for looking at local log files, find the process that is affected, find its log file and less it. Search for certain keywords such as error or critical. Alternatively simply look around the file near the timestamp at which the issue occurred, you might find a message that might point to the root cause.

Alternatives

less is a powerful tool in digging for messages in logs. It does however have alternatives.

$ cat /var/log/syslog
$ cat /var/log/syslog | grep error

cat is great for looking at out of a file, it can be combined with grep to get the same result.

$ tail -f /var/log/syslog
$ tail -f /var/log/syslog | grep error

tail is great for tailing log files and streaming output to stdout.

$ more /var/log/syslog

Before less came more, essentially less is a better version of more.

Conclusion

In the next part we are going to cover df & du for debugging applications. These parts will be released on a weekly basis, if you want to skip the queue please buy the book here:

https://www.amazon.com/dp/B0BJC4Y1N1

Please leave comments and share your outage debugging stories.

--

--

Neeran Gul

Industry veteran providing strong mentorship and sharing experiences.