# forward port without iptables
socat TCP4-LISTEN:8080,fork TCP4:1.1.1.1:8080# create a RAM disk
mount -t tmpfs -o size=512m tmpfs /mnt/tmpfs# save image image-name
sudo docker save image-name | gzip > /tmp/image-name.img.gz# load image image-name
gunzip -c /tmp/image-name.img.gz | sudo docker load # find which branches contain a commit
git branch --contains <commit># revert last commit and keep modified files
git reset --soft HEAD^# perform 1000 HTTP requests using 5 concurrent threads
ab -n 1000 -c 5 http://localhost:8080/api/version
# this requires Apache HTTP server benchmarking tool which is available though
# package httpd-tools in RHEL/CentOS and apache2-utils in Debian/Ubuntu# get thread dump for PID 12345
jstack -l 12345 > /tmp/thread.log# get heap summary for PID 12345
jmap -heap 12345 > /tmp/heap.log# get heap histogram for PID 12345
jmap -histo 12345 > /tmp/histogram.log# get heap dump for PID 12345
jmap -dump:format=b,file=/tmp/heap.bin 12345# force garbage collection for PID 12345
jcmd 12345 GC.run# enable JMX remote monitoring
java
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-jar app.jar# test smtp server
swaks -s server -f from -t to -au user -ap pass# scan open ports
nmap 192.168.1.1# scan open ports with service info
nmap -sV 192.168.1.254# scan subnet for devices
nmap -sn 192.168.1.1-255
nmap -sn 192.168.1.1/24# scan subnet for ports
nmap -p22,80,443 192.168.1.1/24# scan subnet for ports with service info
nmap -sV -p22,80,443 192.168.1.1/24# reverse lookup subnet
nmap --dns-servers 8.8.4.4,8.8.8.8 -sL 209.132.183.105/24# get info
nvme list
nvme id-ctrl /dev/nvme0n1 -H# secure erase
# (first check if "Crypto Erase Supported as part of Secure Erase" is available)
nvme format /dev/nvme0n1 --ses 2# show running queries
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;# show table statistics
SELECT relname, seq_scan, idx_scan, n_tup_ins, n_tup_upd, n_tup_hot_upd, n_tup_del, n_tup_newpage_upd, autovacuum_count, last_autovacuum
FROM pg_stat_user_tables
ORDER BY n_tup_ins desc;# terminate connections
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE datname = '<database name>';# copy database
CREATE DATABASE "new" WITH TEMPLATE "old";# remove first line of file
sed -i '1d' file.txt
# remove second line of file
sed -i '2d' file.txt
# remove first and second line of file
sed -i '1d;2d' file.txt
# remove last line of file
sed -i '$d' file.txt# copy file from local to remote without scp
cat local.txt | ssh user@example.com "cat > /tmp/remote.txt"# copy file from remote to local without scp
ssh user@example.com "cat /tmp/remote.txt" > local.txt# SSH's X11 Forwarding (for instance xterm)
ssh -X user@example.com "xterm"
# the remote machine must have:
# 1. sshd X11 Forwarding enabled ("X11Forwarding yes" at /etc/ssh/sshd_config)
# 2. xorg-x11-xauth package installed (yum install xorg-x11-xauth)# SSH socks5 proxy
ssh -D 9050 user@domain.com
curl --socks5 127.0.0.1:9050 ipinfo.io
proxychains curl ipinfo.io
proxychains firefoxssh-agent | tee ~/.ssh/agent.env # once
source ~/.ssh/agent.env # multiple terminals# create named session
tmux new -s session-name# dettach session (inside tmux)
Ctrl+b d# list session
tmux ls# attach session
tmux attach -t session-name
tmux attach -t 0# windows
Ctrl+b c Create a new window (with shell)
Ctrl+b w Choose window from a list
Ctrl+b 0 Switch to window 0 (by number )
Ctrl+b , Rename the current window# panes
Ctrl+b % Split current pane horizontally into two panes
Ctrl+b " Split current pane vertically into two panes
Ctrl+b o Go to the next pane
Ctrl+b ; Toggle between the current and previous pane
Ctrl+b x Close the current pane# create Tor connection to explicit country exit node
echo -e "ExitNodes {us}\nStrictNodes 1" | tor -f -# use curl
curl --socks5 127.0.0.1:9050 ipinfo.io# use torsocks
torsocks curl ipinfo.io# use proxychains
proxychains curl ipinfo.io# use chromium
chromium --user-data-dir=/tmp/x --proxy-server="socks5://127.0.0.1:9050"# download playlist to mp3
youtube-dl -x --audio-format="mp3" --audio-quality="160k" --add-metadata --continue "https://www.youtube.com/playlist?list=PL7x1NEEwqJNvSGCXac6zGxERF9CDcsOK9"