Last active
April 20, 2021 05:42
-
-
Save hacktor/0dd346b52e2a808e15364ad031feec4d to your computer and use it in GitHub Desktop.
bash functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
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