Skip to content

Mark's Cheatsheet on everything cheatsheety (So I can close some tabs)

Notifications You must be signed in to change notification settings

MarkNBroadhead/cheatsheet

Repository files navigation

cheatsheet

Mark's Cheatsheet on Everything Cheatsheety (So I can close some tabs)

Starting off with a link of cheatsheets/guides I use regularly

Useful commands

Linux

Systemd

systemctl <command> <service-name>

commands: start, stop, restart enable, disable, status, is-active, is-enabled, is-failed

systemctl list-units --all Lists all active units systemd knows about whether active or not

More commands on Digital Ocean guide

Ubuntu

Package Manager

  • apt list --installed

  • Clear out all old kernels (USE WITH CAUTION) found here

    dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge

Alpine

Init

  • rc-update add <service> <runlevel> (skipping runlevel will default to the default runlevel)
  • rc-update del <service> <runlevel>
  • rc-service <service> <start stop restart>
  • rc <runlevel>
  • reboot
  • halt
  • Available runlevels
    • default, hotplugged, manual, sysinit, boot, single, reboot, shutdown

Package Manager

  • apk add <package>
  • apk del <package>
  • apk update Updates repository caches
  • apk upgrade Upgrades all packages on the system
  • apk search -v <search string>
  • apk info -a <package> Get info on package
  • apk info Lists all installed packages

Network

  • Show listening ports netstat -ap tcp | grep -i "listen" or sudo lsof -PiTCP -sTCP:LISTEN

Utilities

Vim

  • Elevate vim to write over read-only file :w !sudo tee %
  • Find and replace :%s/<replace this>/<with this/g
  • Delete matching lines :g/profile/d
  • Delete non-matching lines :v/profile/d or :%g!/profile/d
  • Set paste mode :set paste & :set nopaste
  • Folding - :help usr_28
  • Copy certain lines into a register (register is optional) :13,19y a
  • Copy number of lines 5Y - copies 5 lines
  • Paste from register a under line 7 :7pu a
Macros
  • q<letter><commands>q record macro
  • <number>@<letter> execute macro
  • :%norm! @<letter> execute on all lines
  • :5,10norm! @<letter> execute on lines 5-10
  • :g/pattern/norm! @<letter> execute on all lines matching pattern
Folding

All folding commands start with z.

  • zfap F-old creation - A Paragraph
  • zo Fold O-pen
  • zc Fold C-lose

SSH

scp transfer local file scp file.txt user@hostname:/remote/folder/

Port forwarding

Jails

  • jls List jails
  • jexec 1 /bin/tcsh Access jail 1 ssh -L <local_port>:<service_host>:<service_port> -p <ssh_server_port> -l <ssh_server_username> -N <ssh_server_host>

Bash

  • <command> !* run new command with last arguments
  • DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" get directory of current file.
  • cat V{0..100}*.sql Cat files using numerical sorting instead of alphabetical
  • Last # arguments:
    • !$ last
    • !:* or !* all
    • !:1 or !^ 1st
    • !:1-3 1-3
    • !:2-* 2-last
    • $:0 The command, no args
  • Ensure parameter/envvariable is set ${2?Error message} For env var, replace the 2.
  • Set var with fallback DIR=${MY_ENV_VAR:-$DEFAULT_DIR}

ZSH

  • cat V*.sql(n) Cats files using numerical sorting instead of alphabetical

IntelliJ

  • CMD+Shift+A "Find Action"
  • Shift x2 "Search Anywhere"

macOS

Copy/Paste clipboard

pbcopy pbpaste ex. cat /etc/ssh/sshd_config | pbcopy

CLI Utils

git

Staging

  • git add -p interactive staging
  • git add -i

Logs

  • git log --follow -p -- <file> File history with diffs of each change, follows renames

Rebasing

rebase x commits onto another-branch

  • git checkout -b staging-branch
  • git rebase -i <SHA or HEAD~<numcommits>> --onto another-branch

Reorganize commits into new commits

  • git checkout -b staging-branch
  • git rebase -i <sha> Commit SHA will be one before the ones you want to edit. Can also use HEAD~numcommits format.
  • In git-rebase-todo, change all but top to s or squash. You can also do this selectively with e or edit.
  • Save commit messages as is.
  • git reset HEAD~ to unstage all changes from squashed commits.
  • Stage and create new commits.
  • git rebase --continue

External CLI tools

Get IP address

  • curl ifconfig.co returns public ip address

About

Mark's Cheatsheet on everything cheatsheety (So I can close some tabs)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published