Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Last active July 27, 2021 09:14
Show Gist options
  • Save miraculixx/c00cfb9fab8833e901dfed0a3cf28b65 to your computer and use it in GitHub Desktop.
Save miraculixx/c00cfb9fab8833e901dfed0a3cf28b65 to your computer and use it in GitHub Desktop.
useful linux utilities
function topnfiles {
# show top n files by size
# Usage: $ topnfiles <dir> <n>
# https://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/
du -hsx ${1:-.}/* | sort -rh | head -${2:-10}
}
# show home dir size, available space
alias hdf='df -h | grep home'
# kubernetes utilities
function podlog() {
# get podlog from partial podname
# Usage: podlog <partial podname>
pod=`kubectl get pods --all-namespaces | grep "$1" | tr -s ' ' | cut -d ' ' -f 2 | head -n1`
ns=`kubectl get pods --all-namespaces | grep "$1" | tr -s ' ' | cut -d ' ' -f 1 | head -n1`
shift 1
kubectl logs --namespace $ns $pod $*
}
function despod() {
# describe pod from partial podname
# Usage: despod <partial podname>
kubectl get pods -o name | grep $1 | cut -d / -f 2 | head -n1 | xargs -L1 -I{} kubectl describe pod {} | less
}
function podssh() {
# ssh into a pod from partial podname
# Usage: podssh <partial podname> <cmd|bash>
pod=`kubectl get pods --all-namespaces | grep -E "\s$1.*" | grep -i "running" | tr -s ' ' | cut -d ' ' -f 2 | head -n1`
ns=`kubectl get pods --all-namespaces | grep -E "\s$1.*" | grep -i "running" | tr -s ' ' | cut -d ' ' -f 1 | head -n1`
shift 1
cmd=${@:-bash}
kubectl exec -it --namespace $ns $pod -- $cmd
}
function pods() {
# get list of pods
kubectl get pods $*
}
function svcs {
# get list of services
kubectl get services
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment