Avantguard Computer & Security Systems

Cheat Sheets

Vim Cheat Sheet

Modes

  • i — insert mode
  • Esc — normal mode
  • v — visual mode
  • : — command mode
  • h j k l — left, down, up, right
  • gg — go to top of file
  • G — go to bottom of file
  • Ctrl+f — page down
  • Ctrl+b — page up
  • 0 — start of line, $ — end of line
  • /pattern — search forward, n — next match

Editing

  • dd — delete line
  • yy — yank (copy) line
  • p — paste below cursor
  • u — undo
  • Ctrl+r — redo
  • :%s/old/new/g — replace all occurrences

Files

  • :w — write (save)
  • :q — quit
  • :wq — save and quit
  • :q! — quit without saving

Systemd Cheat Sheet

# Service management
systemctl start <service>
systemctl stop <service>
systemctl restart <service>
systemctl reload <service>
systemctl enable <service>
systemctl disable <service>
systemctl status <service>

# View logs
journalctl -u <service>
journalctl -u <service> -f       # follow
journalctl -u <service> --since "1 hour ago"

# List units
systemctl list-units --type=service
systemctl list-units --state=failed

Bash Cheat Sheet

# Variables
VAR="value"
echo $VAR
echo ${VAR:-default}     # use default if unset

# Conditionals
if [ -f /path/to/file ]; then
  echo "file exists"
fi

if [ "$VAR" = "value" ]; then
  echo "match"
fi

# Loops
for i in 1 2 3; do echo $i; done
for f in /etc/*.conf; do echo $f; done

while read line; do
  echo "$line"
done < file.txt

# Functions
myfunc() {
  local arg1="$1"
  echo "arg: $arg1"
}

# Redirect both stdout and stderr
command > output.log 2>&1

# Background job
command &
wait    # wait for all background jobs