Bash Cheatsheet¶
Login with kinit¶
printf $PASSWORD | kinit $USERNAME@CONTOSO.COM
klist
Looping & IFS¶
IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries.
THINGS="foo \
bar \
baz"
for THING in THINGS; do
echo $THING
done
IFS=';'
THINGS="foo;\
bar;\
baz"
for THING in THINGS; do
echo $THING
done
Unset¶
# remove function
unset -f SomeFunction
Find¶
# find files in ./dir
find ./dir -type f
# find files in ./dir but not with name hidden
find ./dir -type f -not \( -name hidden \)
-maxdepth 1
-type d
-name '*.md'
-printf "\"%p\" "
Get top 10 IP address with count of established connections¶
ss -tnp | awk '
{
gsub(/\[::ffff:/, "", $5); gsub(/\]/, "", $5);
split($5, remote, ":");
print remote[1];
}' | sort | uniq -c | sort -nr | head -n 10