All posts by Tomislav Vlahović

Linux Cheat Sheet

PROCESS BASICS

ps auxww -H

All processes, with params + hierarchy

pgrep -fl $PROCESS_NAME

Filtriraj procese

strace -f -p $PID

What is a process doing?

lsof -p $PID

What files does a process have open?

watch 'ps aux | grep $PROCESS_NAME'

Keep an eye on a process

MEMORY

free -m
cat /proc/meminfo

How much mem is free?

vmstat 1

Are we swapping?

ps aux --sort=-resident|head -11

List the top 10 memory hogs

DATABASES

pt-query-digest --processlist h=localhost --print --no-report --user xxxx --password *****

“Tail” all queries hitting mysql. More

ssh -L 3307:localhost:3306 user@hostname -N

Connect to production mysql locally on port 3307 via ssh

DISK/FILES

iostat -xnk 5

Check reads/writes per disk

find . -size +100M

Find files over 100MB

find . -mtime -7

Find files created within the last 7 days

find . -mtime +14 -type f -name '*.gz'

Find files older than 14 days

find *.gz -mtime +14 -type f -exec rm {} \;

Delete files older than 14 days

tail -f file.log | grep 192.168.1.1

Monitor a log file for an IP or anything else

NETWORK

lsof -nPi tcp

TCP sockets in use

ip addr
ifconfig
iwconfig

Get IP/Ethernet info

mtr google.com

Traceroute with stats over time (top for traceroute)

tcptraceroute google.com

Traceroute using TCP to avoid ICMP blockage

iftop

Show traffic by port

netstat -tlnp

Show all ports listening with process PID

Izvor: http://rubytune.com/cheat