Cheat Sheets Unix


Health Monitoring

See top 10 processes

 ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 

View "top" by process name

top -p `pgrep someprocess | tr "\\n" "," | sed 's/,$//'`

Show files opened by process

lsof -p pid

List directory sizes

du -skh * | sort -n

Search

Find string in files.

find . -type f -exec grep -l 'some string' {} \;
grep -H 'some string' /dir/* -R | cut -d: -f1 

File manipulation

Gunzip and untar in one line.

tar -zxvf /path/to/file.tar.gz

Crontab

List crontabs for all users.

for user in $(cut -f1 -d: /etc/passwd); do echo $user && crontab -u $user -l; echo " "; done

Misc

Bypass paid wi-fi.

ifconfig en1 | grep ether
arp -a
sudo ifconfig en1 ether [mac address to spoof]