Show Menu
Cheatography

Sheeeeeeeeeeet Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

vim

zo
open folded text
zc
close folded text
zr
unfold one level
zm
fold one level
zR
unfold all
zM
fold all
c-w w
switch window
ctrl-w s
split windows
c-w v
split vertically
c-w q
quit window
:set list
show characters
do
diff obtain
dp
diff put
:set diffop­t+=­iwhite
avoid whitespace in diff
:diffu
refresh differ­ences
Auto wrap text:
1. :set textwi­dth=80
2. select text in visual mode
3. gq

regex

[^bg]
caret negates expression
\s
whitespace
\S
not whitespace
\d
digit
\D
not digi
\w
word
\x
hexade­cimal digit
\O
octal digit
(?:...)
Passive (non-c­­ap­t­u­ring) group

screen

C-a S
split horizo­ntally
C-a | or C-a V
split vertically
C-a tab
jump to next region
C-a X
close region

Syslog severity levels

0
emerg
Emergency
1
alert
Alert
2
crit
Critical
3
err
Error
4
warning
Warning
5
notice
Notice
6
info
Inform­ational
7
debug
Debug

IO redire­ction

Output of cmd2 as file input to cmd1:
cmd1 <(c­md2)
Stderr of cmd to file:
cmd 2> file
Stdout to same place as stderr:
cmd 1>&2
All output of cmd to file:
cmd &> file
stderr of cmd1 to cmd2:
cmd1 |& cmd2

DH Groups

DH Group 1: 768-bit group
DH Group 2: 1024-bit group
DH Group 5: 1536-bit group
DH Group 14: 2048-bit group
DH Group 15: 3072-bit group
DH Group 19: 256-bit elliptic curve group
DH Group 20: 384-bit elliptic curve group
IPsec VPN:
UDP 500 (IKE includes ISAKMP)
UDP 4500 (NAT traversal)
IP protocol 50 (ESP)
IP protocol 51 (AH)

nmap

-sn
no port scan
-PE
only ICMP echo for host disc.
-Pn
no ping
-n
no name resolve
-p80,443
scan port 80 and 443
-p-
scan all ports
-e <I­FAC­E>
use specified interface
-O
OS detection

tcpdump

-A
payload in ASCII
-c <co­unt>
exit after count packets
-e
print link level headers
-G <n>
rotate dump file every n sec
-s <le­n>
snip first len bytes per packet
-S
absolute TCP seq numbers
 

random

Back­uppaa ACL:t:
getfacl -pR /joku/­hak­emisto > permis­sio­ns.acl
setfacl --rest­ore­=pe­rmi­ssi­ons.acl
Listaa ladattavat moduul­it:
cat /lib/m­odu­les­/$(­uname -r)/mo­dul­es.dep
TCP portit:
0-1023 - well-known ports
1024-­49151 - registered port
49152­-65535 - dynamic / private ports
SSL netcat:
openssl s_client -connect localh­ost­:995
Maalaa osumat:
grep -E --color '(^|ha­ku)'
Unix epoch aika:
date +%s
date -d @12687­27836

sed: address notation

n
line number
$
last line
/regexp/
lines matching the pattern
addr1,­addr2
range of lines
10~2
start 10, then by 2 intervals
addr1,+n
addr1 and following n lines
addr!
all lines except addr
sed -n '1,5p' file.txt
sed '1,5­s­/ol­d/new' file.txt

sed: editing commands

=
output line number
a
append text after line
d
delete line
p
print line, use -n to override
s/old/new/
substitute
sed "1,10 d" file.txt
sed "­/snmp/ a text to append­" file.txt
sed -n "­/snmp/ =" file.txt
sed -i -e '/suod­ata­/{s­/et­si/­kor­vaa/}' file
 

Bash: space split

INPUT: "word" "spaces yo"
$*   : $1 = word, $2 = spaces,    $3 = yo
"$*" : $1 = word spaces yo, $2 =, $3 =
$@   : $1 = word, $2 = spaces,    $3 = yo
"$@" : $1 = word, $2 = spaces yo, $3 =

Bash: for in C Form

for (( i=0; i<5; i=i+1 )); do
  echo $i
done

Bash: variable expansions

Return $para­meter or "­wo­rd­" if empty:
${par­ame­ter­:-w­ord}
Previous + set variable value if it's unset:
${par­ame­ter­:=w­ord}
Exit script with error message if empty:
${par­ame­ter­:?error message}
Results nothing if empty. If not empty, substitute and don't change variable value:
${par­ame­ter­:+w­ord}

Return variable names:
${!pr­efix*}
Return string length:
${#pa­ram­eter}
Return substr­ing:
${par­ame­ter­:of­fset}
${par­ame­ter­:of­fse­t:l­ength}
Remove leading substr­ing:
${par­ame­ter­#pa­ttern} (shortest match)
${par­ame­ter­##p­att­ern} (longest match)
Remove trailing substr­ing:
${par­ame­ter­%pa­ttern} (shortest match)
${par­ame­ter­%%p­att­ern} (longest match)

Search and replace. If string not set, delete matched text.
Only first occure­nce:
${par­ame­ter­/pa­tte­rn/­str­ing}
All occure­nces:
${par­ame­ter­//p­att­ern­/st­ring}
Match required at the beginning of string:
${par­ame­ter­/#p­att­ern­/st­ring}
Match required at the end of string:
${par­ame­ter­/%p­att­ern­/st­ring}

Bash: number bases

number
base 10 integer
0num­ber
base 8 octal
0xnu­mber
base 16 hexade­cimal
base­n­umber
number is in base
echo $((0xff))
255
echo $((2#1­111­1111))
255

Bash: ternary operator

expr1?expr2:expr3
If expression exp­r1 evaluates to be non-zero (arith­metic true) then exp­r2, else exp­r3.

Bash: case conversion

${para­met­er,,}
All to lowercase.
${para­meter,}
First char to lowercase.
${para­met­er^^}
All to uppercase.
${para­meter^}
First char to uppercase.

Bash: tests

Pattern matchi­ng:
[[ "­foo.ba­r" == foo.* ]]
Rege­xp:
[[ "­$IN­T" =~ ^-?[0-9]+$ ]]
Arit­hmetic truth tests:
(( ((INT % 2)) == 0))