October 20, 2020
Bash tips
General
kill procces by port
sudo kill $(sudo lsof -ti:port)
create symlink
ln -sf /path/to/file /path/to/symlink
open url from bash
xdg-open http://google.com
bash loop
for (;;); do command; command-2; done
output timestamps
ts # timestamp ts -i # each output duration ts -s # time taken from start
find & replace in all files in folder & subfolders
sudo kill $(sudo lsof -ti:port) ack -l 'pattern' | xargs perl -pi -E 's/pattern/replacement/g'
visualize git repo development
gource --stop-at-end --hide filenames,usernames,dirnames -1920x1080 -s 0.5 -o - | ffmpeg -y -r 30 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -threads 0 -bf 0 gource.mp4 -crf 0
list opened ports and its process names
netstat -nlpt
postgres
install psql
sudo apt install postgresql postgresql-contrib
drop connections for dbname
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'dbname' AND pid <> pg_backend_pid();
create full duplicate of dbname named dbname_copy with db_user owner
create database dbname_copy WITH TEMPLATE dbname OWNER owner;
check postgres certificates
curl https://raw.githubusercontent.com/thusoy/postgres-mitm/master/postgres_get_server_cert.py | python3 - host:port | openssl x509 -noout -dates