watch the log file .. its will update in real time
fixed total lines to watch updates
tail -n 100 -f logfile.log
View entire log file with scrolling
Use arrow keys to navigate
Press / followed by text to search
Press q to quit
Display first lines of a log file
head -n 20 logfile.log # Shows first 20 lines
Display last lines without following
tail -n 50 logfile.log # Shows last 50 lines
tail -f logfile.log | grep " ERROR"
Highlight patterns while watching logs
tail -f logfile.log | grep --color=always " ERROR\|WARNING\|INFO"
Search for pattern in log file
grep " Failed login" logfile.log
grep -i " error" logfile.log
Show line numbers with matches
grep -n " exception" logfile.log
Count occurrences of pattern
grep -c " 404 Not Found" access.log
Watch multiple log files simultaneously
tail -f log1.log log2.log log3.log
Monitor logs with timestamps
tail -f logfile.log | while read line; do echo " $( date +%T) : $line " ; done
Filter by time range (using sed)
sed -n ' /2025-01-01 10:00:00/,/2025-02-01 11:00:00/p' logfile.log
Extract specific columns with awk
tail -f logfile.log | awk ' {print $1, $4, $9}' # Print columns 1, 4, and 9
Count unique IP addresses in access log
cat access.log | awk ' {print $1}' | sort | uniq -c | sort -nr
Find the top 10 most common errors
grep " ERROR" logfile.log | cut -d: -f4 | sort | uniq -c | sort -nr | head -10
Analyze HTTP status codes
cat access.log | grep -o ' HTTP/[0-9.]* [0-9]*' | cut -d' ' -f2 | sort | uniq -c | sort -nr
Calculate average response time
awk ' {sum+=$10; count++} END {print "Average response time:", sum/count, "ms"}' access.log
Archive logs older than 7 days
find /var/log -name " *.log" -type f -mtime +7 -exec gzip {} \;
mv logfile.log logfile.log.1
touch logfile.log
chmod 644 logfile.log
split -b 100M large_logfile.log segment_
View logs with journalctl (systemd)
journalctl -u service-name -f
Apache access log analysis with GoAccess
docker logs --tail 100 -f container_name