Skip to content

Разные советы

Отслеживать частоты ядер/потоков

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

Показать устройства PCIe и их скорость подключения

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

Архивирование с визуализацией

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

# или с жатием
tar -czf - /root | pv -s $(du -sb | grep -o '[0-9]*') > /root.tgz

Активация подсказкок bash

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

Поиск зомби процессов

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

# показать все
ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }' | xargs -L1 pstree -ps

Если скучно

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

# home cat
apt install oneko -y && oneko

Nginx access.log

shell
apt install pv -y

# количество запросов/сек в реальном времени
tail -f /var/log/nginx/access.log | pv -lr > /dev/null

# среднее количество запросов/сек в реальном времени за определенный промежуток времени
tail -f /var/log/nginx/access.log | pv -lr -i 60 > /dev/null

# вывод с сортировкой
cat /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -n

Тестирование производительности

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

# Siege тест
siege -c 100 -r 500 -t5M -v http://localhost

# Обход по всем ссылкам с сохранением
wget -rkpE http://localhost

Logstalgia - визуализация access.log

shell
ssh user@host "tail -f /var/log/nginx/access.log" | logstalgia --sync -x -f
# слушать сетевой интерфейс
urlsnarf -ni eth0 > /tmp/access.log

Принудительно завершить SSH-сессию

~. -> enter

Это полезно, если сессия зависла или есть "лаг" в терминале

Git

Удаление файла из истории

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

Удалить из индекса

shell
git rm --cached example.txt

Откат к точке с сохранением изменений

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

Git Gource визуализация

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