Skip to content

Miscellaneous hints

Monitor CPU core/thread frequencies

shell
watch -n 1 "grep 'cpu MHz' /proc/cpuinfo"

Show PCIe devices and their connection speeds

shell
sudo lspci -vv | grep -P "[0-9a-f]{2}:[0-9a-f]{2}\.[0-9a-f]|LnkSta:"

Archiving with Progress Visualization

44.3MB 0:00:27 [1.73MB/s] [>..........................] 0% ETA 13:36:22

shell
tar -cf - /root | pv -s $(du -sb | grep -o '[0-9]*') > /root.tar

# or with compression
tar -czf - /root | pv -s $(du -sb | grep -o '[0-9]*') > /root.tgz

Enable bash autocompletion

shell
apt-get install bash-completion && \
echo "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc

Find zombie processes

shell
ps aux | grep 'Z'
pstree -p -s 1234

# show all
ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }' | xargs -L1 pstree -ps

When you're bored

shell
# smart cow
apt install cowsay fortune -y && fortune | cowsay

# home cat
apt install oneko -y && oneko

Analyze Nginx access.log

shell
apt install pv -y

# real-time request rate
tail -f /var/log/nginx/access.log | pv -lr > /dev/null

# average request rate over a time interval
tail -f /var/log/nginx/access.log | pv -lr -i 60 > /dev/null

# sorted output
cat /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -n

Performance testing

shell
# Modern HTTP benchmarking tool
brew install wrk
# 30 seconds, using 12 threads, and keeping 400
wrk -t12 -c400 -d30s --latency http://localhost

# Siege test
siege -c 100 -r 500 -t5M -v http://localhost

# Crawling all links and saving them
wget -rkpE http://localhost

Logstalgia - visualizing access.log

shell
ssh user@host "tail -f /var/log/nginx/access.log" | logstalgia --sync -x -f
# listening on a network interface
urlsnarf -ni eth0 > /tmp/access.log

Force end SSH session press

~. -> enter

Useful when the session is frozen or there's lag in the terminal

Git

Remove a file from history

shell
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch path/to/yourfile" \
  --prune-empty --tag-name-filter cat -- --all

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now --aggressive

git push -f

Remove a file from index

shell
git rm --cached example.txt

Revert to a commit while keeping changes

shell
git reset --mixed c250...9d81

Git Gource visualization

shell
gource ./bildibon -1920x1080 --hide filenames,dirnames,progress,mouse \ 
  --file-filter dompdf --highlight-users --file-idle-time 3333 \
  --output-ppm-stream - | ffmpeg -y -r 60 -f image2pipe \-vcodec ppm -i - \
  -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4