Linux Forensics Commands
1. File and Metadata Analysis
dentifies the type of a file:
file suspicious_fileExtracts human-readable strings from binary files:
strings binary_fileDisplays detailed file metadata, including timestamps:
stat fileExtracts metadata from multimedia files:
exiftool image.jpgCreates a hex dump of a file:
xxd fileDisplays disk usage of a directory or file:
du -sh /var/logLists mounted filesystems:
mountUnmounts a filesystem:
umount /mntShows block devices in a tree structure:
lsblkViews logs from
systemdsystems :
journalctl -u sshdprovides detailed metadata and statistics about a packet capture (PCAP) file
capinfos <file.pcap>jq filters
jq
cat logs.json | jq '.events[] | select(.status == "failed")'
cat logs.json | jq '.events[] | .source_ip'2. System Information Gathering
Hostname and OS details:
hostname
uname -a
cat /etc/os-releaseKernel version and architecture:
uname -r
archSystem uptime and load:
uptime
w3. User Information
Logged-in users and history:
who
last
history
lastlog
passwd -S usernameCheck sudoers file:
cat /etc/sudoers4. Process Investigation
List running processes:
ps aux
top
htop
crontab -lIdentify network-related processes:
netstat -tunap
lsof -iLists open files by processes
lsof -p PIDDisplays memory maps of processes
pmap PIDTraces system calls made by a process.
strace -p PID5. File and Directory Investigation
List directory contents:
ls -alhList hidden files:
ls -a Search for recent file modifications:
find / -type f -mtime -5 2>/dev/nullFind files with specific extensions:
find / -type f -name "*.sh"6. Network Investigation
Active network connections:
ss -tunap
netstat -plantNetwork interface information:
ip addr show
ifconfigDNS resolutions:
cat /etc/resolv.confCapture packets with tcpdump:
tcpdump -i eth0 -w capture.pcapAnalyze packets with tshark:
tshark -r capture.pcap
tshark -n -r packets.pcap -Tfields -e ip.srce -e tcp.srcport -e ip.dst -e tcp.dstport | sort | unig -c7.Package and Service Analysis
List installed packages:
dpkg -l # For Debian-based systems
rpm -qa # For Red Hat-based systemsRunning services:
systemctl list-units --type=service
service --status-all8.Hashing and File Integrity
Calculate file hash:
sha256sum filename
md5sum filenameCompare file hashes:
diff <(sha256sum file1) <(sha256sum file2)Last updated