Notes to Self

Alex Sokolsky's Notes on Computers and Programming

Useful Linux Commands

Top consuming processes

Show the process’ command line

cat /proc/_pid_/cmdline|xargs -0

Show the process’ environment

cat /proc/_pid_/environ | tr '\0' '\n'

Reload DNS resolver

sudo killall -USR2 systemd-resolved

List directories only

Not elegant but works:

ls -lad */|awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}'|sed 's/^ *//'

better but results in a leading whitespace:

ls -lad */|awk '{out = ""; for (i = 9; i <= NF; i++) {out = out " " $i}; print out}'

best:

ls -ld */|cut -c 53-

more options

URL-decode

echo -n "%21%20" | python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()));"

Scripting

Troubleshooting

A server is acting slow at 2am? Here are the commands to run — in this order:

  1. top -c - Who’s eating CPU? What’s the load average vs core count?
  2. iostat -xz 1 5 - Is it disk I/O? High await or %util tells the real story.
  3. free -h - Is swap being used heavily? That’s your first red flag.
  4. ss -tulnp - What’s listening? Anything unexpected open?
  5. df -hT - Disk full?
  6. dmesg | tail -30 - Kernel / hardware errors show up here first.
  7. journalctl -p err -n 50 - Last 50 error-level logs.