Useful commands

From Wiki
Revision as of 16:57, 20 June 2018 by Microchip08 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

(draft) Useful commands

Git

# force a repo to match remote
git checkout master && git fetch --all && git reset --hard origin/master
# how to gerrit
git commit --all [--amend]
git show HEAD
git review
# get latest for all submodules
git submodule foreach git pull origin master
# move top commit to branch
git branch foo
git reset --hard HEAD
git checkout foo

Date

date +%s # current timestamp

Sysadmin

# expire an password
chage -d 0 foo
# get running processes
ps aux
ps -ely
# add user to group
usermod -aG sudo foo
dpkg -l # package info
dpkg -L # package contents
apt-cache policy $package # get version to be installed
# rm "manually installed" flag
apt-mark auto package-name
# get key -- c.f http://pgp.cs.uu.nl/
gpg --recv-keys 0x83D79CE73F41F985 --keyserver keyserver.ubuntu.com
ntpd -gq # sync and quit
sudo sntp -s time.google.com
openssl x509 -noout -in /etc/ssl/certs/example.com.crt -fingerprint -sha256
# avoid kill -9 -- http://www.smallo.ruhr.de/award.html#uuk9letter
kill -15 # SIGTERM
kill -2  # SIGINT
kill -1  # SIGHUP

Kubernetes

kubectl get pods --field-selector=status.phase=Running"
kubectl get pods -l app=toot -o jsonpath="{..status.phase}"
# Get a shell
kubectl exec -it my-pod --container main-app -- /bin/bash

Networking

tcpdump ip proto \\icmp # echo pings to terminal
# count TCP states on :80
netstat -an | grep ':80\b' | awk '/tcp/ {print $6}' | sort | uniq -c
sudo netstat -plnt | grep ':80'
ip route add default via 198.51.100.1
iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 3000

X

# purge font cache
sudo fc-cache -fv
# tab to a window then press a key:
xdotool search firefox windowactivate --sync key F5 # when crossing the room to refresh is too much effort
export DISPLAY=:0
google-chrome http://example.com # open chrome if open, else open new tab

Freeswitch

# send a fax
originate sofia/external/1000@example.com &txfax(/tmp/txfax.tiff)

Code snippets

Vagrant.configure("2") do |config|
  config.vm.box = "foo/bar"
  config.vm.provision :shell, path: "bootstrap.sh"
end
$.ajax( {
	url: mw.util.wikiScript( 'api' ),
	type: 'POST',
	dataType: 'json',
	data: {
		format: 'json',
		action: 'edit',
		title: 'User:' + mw.config.get( 'wgUserName' ) + '/global.js',
		text: '',
		token: mw.user.tokens.get( 'editToken' )
	}
} );
( while [ "true" ];do echo -ne '/\b' ; sleep 0.05; echo -ne '-\b' ; sleep 0.05; echo -ne '\\\b' ; sleep 0.05;echo -ne '|\b' ; sleep 0.05;done;echo -ne ' \b' ) &
while true; do echo $RANDOM$RANDOM | tail -c 8 | pbcopy; done

Colors

Color FG BG
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47
<ESC>[{attr1};...;{attrn}m