Skip to content

Instantly share code, notes, and snippets.

@DiegoFleitas
Forked from garystafford/remove_swap.sh
Created July 20, 2021 17:12
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 DiegoFleitas/faf3e922a1a938624c514d7601f93a22 to your computer and use it in GitHub Desktop.
Save DiegoFleitas/faf3e922a1a938624c514d7601f93a22 to your computer and use it in GitHub Desktop.
From my blog post, Scripting Linux Swap Space: Scripting Linux Swap Space
#!/bin/sh
# does the swap file exist?
grep -q "swapfile" /etc/fstab
# if it does then remove it
if [ $? -eq 0 ]; then
echo 'swapfile found. Removing swapfile.'
sed -i '/swapfile/d' /etc/fstab
echo "3" > /proc/sys/vm/drop_caches
swapoff -a
rm -f /swapfile
else
echo 'No swapfile found. No changes made.'
fi
# output results to terminal
cat /proc/swaps
cat /proc/meminfo | grep Swap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment