Skip to content

Instantly share code, notes, and snippets.

View xeruf's full-sized avatar
🚵‍♂️
Exploring

Janek xeruf

🚵‍♂️
Exploring
View GitHub Profile
@xeruf
xeruf / stopswap
Last active December 11, 2019 07:08 — forked from Jekis/toggle_swap.sh
Empty Swap. Can be put into ~/.bashrc or similar and then called with stopswap.
mem_stat() {
mem_total="$(free | head -2 | tail -1 | awk '{print $2}')"
mem_free="$(free | head -2 | tail -1 | awk '{print $4}')"
mem_percentage=$((mem_free * 100 / $mem_total))
swap_total="$(free | tail -1 | awk '{print $2}')"
swap_used="$(free | tail -1 | awk '{print $3}')"
swap_percentage=$(($swap_used * 100 / $swap_total))
echo -e "Free memory:\t$((mem_free / 1024))/$((mem_total / 1024)) MB\t($mem_percentage%)"
echo -e "Used swap:\t$((swap_used / 1024))/$((swap_total / 1024)) MB\t($swap_percentage%)"