Using Logs to Help You Track Down an Issue in Linux

Soban Malik
4 min readFeb 26, 2024

--

Viewing logs on Linux

On Linux machines, logs are stored in the /var/log directory. There are lots of log files in this directory, and you can view them with this command:

ls /var/log

We’re interested in syslog for the moment. The logs on Linux can be viewed like any text file; you can use the command below to view the contents of Syslog:

sudo cat /var/log/syslog

The log contents are super long, so you’ll have to scroll through the logs to look for the five entries that are relevant to this lab. The logs are entered chronologically, and the logs that you’ll need to fix should be timestamped around the time that the lab started. For convenience, all of the log entries you need to fix contain the phrase “Qwiklab Error”. Knowing this, you could also filter out the relevant labs using the grep command.

We’ll walk through addressing one of the log’s issues, then the other four will be up to you!

Low disk space!

Here’s the log entry we will be dealing with first:

This error indicates that your computer is running out of memory due to a super large file. Unfortunately, it doesn’t indicate which file is causing the problem, so you’ll need to find it. Luckily, Linux has an easy way to find the largest files on your file system. The du command can be used to list all files in a directory (recursively through subdirectories, too), which you can sort by size to find the largest files. By piping the output of du (using the “|” symbol) to the sort command, you can sort the output by file size. The “-n” and “-r” flags tell sort to treat the string output on each line as a number (the file size), and to sort in reverse order so that the largest files are listed first. By piping the output of this into the head command, you can print out only the top few results (you can specify how many to output by adding “-n [NUMBER]” to the end of the command).

The command below uses du, sort, and head to show the top five largest files, starting from your /home directory:

sudo du -a /home | sort -n -r | head -n 5

You can see that the largest file in your home directory is /home/lab/storage/ultra_mega_large.txt, at about 5GB. This isn’t an important file, but it’s taking up a lot of space, so you can delete it to fix the disk space error:

sudo rm /home/lab/storage/ultra_mega_large.txt

Remove corrupted file:

sudo rm {path and file name }

Update VLC:

sudo apt-get upgrade VLC #to upgrade the vlc palyer

sudo apt --fix-broken install # if any error occur to upgrade try this

End malicious processes:

ps -ax # to see all the running process or 
sudo kill {process id} # to kill the process or terminate it

Change permission of the secret file to public:

sudo ls -la {path file } #to see the permission of the file 
sudo chmod 777 {path +file name } #give all permission of the file 

conclusion:

Utilizing logs in Linux is indispensable for troubleshooting, offering a detailed record of system activities and errors. By analyzing log files, administrators can efficiently pinpoint issues, aiding in swift resolution and system optimization. Incorporating log analysis into troubleshooting workflows enhances system stability and performance, fostering proactive maintenance and problem resolution.

--

--

Soban Malik
Soban Malik

No responses yet