Mark's Cheatsheet on Everything Cheatsheety (So I can close some tabs)
Starting off with a link of cheatsheets/guides I use regularly
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
-
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
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>reboothalt- Available runlevels
- default, hotplugged, manual, sysinit, boot, single, reboot, shutdown
apk add <package>apk del <package>apk updateUpdates repository cachesapk upgradeUpgrades all packages on the systemapk search -v <search string>apk info -a <package>Get info on packageapk infoLists all installed packages
- Show listening ports
netstat -ap tcp | grep -i "listen"orsudo lsof -PiTCP -sTCP:LISTEN
- 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/dor:%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
q<letter><commands>qrecord 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
All folding commands start with z.
zfapF-old creation - A ParagraphzoFold O-penzcFold C-lose
scp transfer local file scp file.txt user@hostname:/remote/folder/
Port forwarding
jlsList jailsjexec 1 /bin/tcshAccess jail 1ssh -L <local_port>:<service_host>:<service_port> -p <ssh_server_port> -l <ssh_server_username> -N <ssh_server_host>
<command> !*run new command with last argumentsDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"get directory of current file.cat V{0..100}*.sqlCat files using numerical sorting instead of alphabetical- Last # arguments:
!$last!:*or!*all!:1or!^1st!:1-31-3!:2-*2-last$:0The 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}
cat V*.sql(n)Cats files using numerical sorting instead of alphabetical
- CMD+Shift+A "Find Action"
- Shift x2 "Search Anywhere"
Copy/Paste clipboard
pbcopy pbpaste
ex. cat /etc/ssh/sshd_config | pbcopy
git add -pinteractive staginggit add -i
git log --follow -p -- <file>File history with diffs of each change, follows renames
rebase x commits onto another-branch
git checkout -b staging-branchgit rebase -i <SHA or HEAD~<numcommits>> --onto another-branch
Reorganize commits into new commits
git checkout -b staging-branchgit 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
Get IP address
curl ifconfig.coreturns public ip address