Terminal

Replace with sed:

sed -E 's/[[:space:]]+IN[[:space:]]+A[[:space:]]+/ /g' <zone >zone2
#or:
sed -i 's/old-word/new-word/g' *.txt

Replace in all files:

find ./ -type f -exec sed -i 's/wheezy/jessie/g' {} \;

Show process limits:

cat /proc/$PID/limits

Show directory size:

du -h --max-depth=1 | sort -hr

Show processes holding deleted files open:

lsof +L1
# or:
lsof | grep "/var" | grep deleted

Globbing:

echo images/!(*.jpg) 

Change locale

iconv -f ISO-8859-1 -t UTF-8 inpfile -o outpfile

Debug regex or bash scripts

cat -A myfile

Forward ssh private key

vim /home/user/.ssh -> ForwardAgent yes
ssh-add

Encrypt file into a 7z with AES256:

7za a -t7z -pPASSWORD secure.7z TingelTangel.png

Set file age:

touch -t 201610251133 test.txt

Fix inotify exhausted ressources:

# Find the culprit:
for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr
# Fix:
vim /etc/sysctl.conf : fs.inotify.max_user_watches=1048576 && sysctl -p

Reset IPMI:

ipmitool bmc reset cold

Display Slab cache:

slabtop

SSH and file transfer

Port-forward trough jump host

ssh -L 8080:localhost:80 user@server -J user@jumphost

Networking

Get HW Mac address:

$ sudo ethtool -P eth1

Show interface statistics:

sudo ethtool -S eth1

Show interface troughput:

sudo dstat -tn -N eth0,eth1,bond0

Debug LACP

apt-get install lldpd
lldpctl

Debug MTU Issues with ping

ping 1.2.3.4 -s 1472 -M do

Ping all IPv6 Hosts Multicast

ping6 -I eth0 ff02::1

Ping all IPv6 Routers Multicast

ping6 -I eth0 ff02::2

SSL

Mozilla SSL config generator

Test TLS handshake:

openssl s_client -connect $Host:$port -tls1

Check that SAN or CN match supplied name:

openssl s_client -servername "mydomain.tld" -connect 127.0.0.1:443 -verify_hostname "mydomain.tld" -verify_return_error

Debug SSL on the server:

sudo ssldump -i eth0 port 443

Mail

Show mailqueue:

sudo mailq

Show single message in queue:

sudo postcat -vq [message id from mailq]

Delete all defered from queue:

postsuper -d ALL deferred

Delete all mails from queue:

postsuper -d ALL

Hardware

Swith IO-Scheduler

echo deadline > /sys/class/block/sdb/queue/scheduler

Check temperature

aptitude install lm-sensors
sensors-detect
watch -n 1 -d sensors

Check ECC Errors:

apt-get install edac-utils
edac-util -v

Safely umount external (USB) HDD:

umount /dev/sdb1
sudo udisksctl power-off -b /dev/sdb

Set display brightness:

sudo brightnessctl -d 'nvidia_0' s 50%

Filesystems

Unmount hanging NFS mounts:

sudo umount -fl /mnt/nfs-mount

Check NFS mounts on NFS Server:

sudo exportfs -ra

Docker

Troubleshoot container network:

sudo docker run -it --rm --network container:< container id > nicolaka/netshoot

Kubernetes

Start netshoot container on specific Node:

kubectl run tmp-shell --overrides='{ "apiVersion": "v1", "spec": { "template": { "spec": { "nodeSelector": { "kubernetes.io/hostname": "$HOSTNAME"}}}}}'  --rm -i --tty --image nicolaka/netshoot -- /bin/bash

show all cilium pods:

kubectl -n kube-system get pods -l k8s-app=cilium -o wide

troubleshoot with hubble:

kubectl -n kube-system exec -ti cilium-abcde --  hubble observe --since 3m --type drop

show cilium health status (shows node-to-node interconnectivity stats)

kubectl -n kube-system exec -ti cilium-abcde -- cilium-health status

source: official troubleshooting docs