Operations 8 min read

Practical Guide to Viewing Logs, Processes, Ports, and System Status on Linux

This article provides a comprehensive, step‑by‑step tutorial on using Linux command‑line tools such as cat, tail, vim, grep, sed, ps, netstat, lsof, and free to efficiently view large log files, locate specific entries, monitor processes and ports, and assess overall system health.

Java Captain
Java Captain
Java Captain
Practical Guide to Viewing Logs, Processes, Ports, and System Status on Linux

1. Viewing Logs

When troubleshooting production issues, checking logs on the server is a common operation. Assuming the log file is named service.log , basic commands include:

cat service.log

tail -f service.log

vim service.log

For large logs (about 1 GB per day), using cat directly will freeze the terminal; tail -f is preferred for real‑time monitoring.

Vim can still be used for quick searches: open the file, press G to jump to the end, then use ? followed by a keyword, navigating with n (next) and N (previous).

To filter specific records, combine cat with grep :

cat service.log | grep 13888888888

To obtain line numbers, add the -n option:

cat -n service.log | grep 13888888888

Once the line number (e.g., 29506) is known, view surrounding context with:

sed -n "29496,29516p" service.log

cat -n service.log | tail -n +29496 | head -n 20

If the result set is large, pipe to more or redirect to a file:

cat service.log | grep 13 | more

cat service.log | grep 13 > /home/sanwai/aa.txt

To count total lines:

cat service.log | wc -l

2. Checking Processes and Ports

Process listing commands:

ps -ef

ps aux

Filter with grep , e.g., ps -ef | grep java . Once the PID is known, terminate with kill -9 <processId> .

Common port inspection commands:

netstat -lntup

l:listening   n:num   t:tcp  u:udp  p:display PID/Program name for sockets

查看当前所有tcp/udp端口的信息

Detailed information for a specific port:

lsof -i:4000

3. Viewing System Status

3.1 TOP – Real‑time Process Monitoring

The TOP command shows running processes and the load average, which represents the average number of processes in the run queue over 1, 5, and 15‑minute intervals.

Linux processes are categorized as blocked, runnable, or running; the sum of runnable and running processes contributes to the load value.

3.2 free – Memory Usage

The free command reports memory usage. Linux treats cached memory as usable, so "available memory" equals free memory plus cached plus buffers.

Understanding Buffer Cache (disk block I/O) and Page Cache (file inode I/O) helps explain how the kernel optimizes I/O performance.

References:

https://www.cnblogs.com/xiashan17/p/7059978.html

https://blog.csdn.net/zhangchenglikecc/article/details/52103737

https://www.cnblogs.com/peida/archive/2012/12/24/2831353.html

Feel free to add more commonly used commands in the comments; further updates will be shared as needed.

operationslinuxcommand-lineSystem AdministrationLog ManagementProcess Monitoringport inspection
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.