Skip to content

Instantly share code, notes, and snippets.

@hacktor
Last active April 20, 2021 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hacktor/0dd346b52e2a808e15364ad031feec4d to your computer and use it in GitHub Desktop.
Save hacktor/0dd346b52e2a808e15364ad031feec4d to your computer and use it in GitHub Desktop.
bash functions
swaptop ()
{
l="${1:-20}";
for file in /proc/*/status;
do
awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file;
done | sort -k 2 -n -r | head -$l
}
urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
}
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
rotate ()
{
[ -f $1.3 ] && mv -f $1.3 $1.4;
[ -f $1.2 ] && mv -f $1.2 $1.3;
[ -f $1.1 ] && mv -f $1.1 $1.2;
[ -f $1 ] && mv -f $1 $1.1
}
@hacktor
Copy link
Author

hacktor commented Apr 19, 2021

  • swaptop: find processes that use the most swap space
  • urlencode: encode url
  • urldecode: decode url
  • rotate: keep backup copies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment