Key Linux commands for log analysis and security monitoring
Key Linux commands for log analysis and security monitoring
By,
ANANDHU S
anandhu-s
1. Log File Analysis & Manipulation:
● grep: Search for patterns within files.
○ grep -E -o "([0-9]{1,3}\.){3}[0-9]{1,3}"
○ grep -E -o
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-
4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[
0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
/var/log/nginx/access.log
○ grep -E -o
"(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9]{1,4}:){7
addresses.
○ grep -E -o
"(?:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})"
○ grep -E -o
"([a-fA-F0-9]{32}|[a-fA-F0-9]{40}|[a-fA-F0-9]{64})"
(only filenames).
characters.
characters.
errors in real-time.
logs.
directory, even when they are rotated. The capital F is very useful, as it
continues to follow the file even if it is removed and recreated, which log
rotation does.
Monitor firewall logs and extract specific fields (e.g., source and
destination IP addresses).
lines.
○ head -c [number] filename: This option displays the first specified
number of bytes. This can be useful when dealing with binary files or when
head will display the first 10 lines of each file, with headers indicating
configurations.
○ cat /etc/passwd: While you should be cautious with this file, cat
allows for a quick look at user accounts. (Remember that shadow files
○ cat filename | md5sum: Calculate the MD5 hash of a file. This can
○ md5sum filename: A more direct way to get the md5sum, without the
cat command.
● less: View file content one screen at a time (more efficient than
cat for large files).
third columns.
containing "error."
separator.
● sed: Stream editor for text manipulation.
○ sed 's/old/new/g' /var/log/file.log: Replace "old" with "new"
globally.
specific host.
○ nslookup google.com
3. System & User Management:
● ps: Display running processes.
○ find /var/log -mtime -1: Find files modified on the last day.
4. Security Specific:
● iptables: Firewall configuration (often replaced by nftables).
<--------------------------------------------------- END -------------------------------------------------------->