diff --git a/disk_cleanup_linux b/disk_cleanup_linux new file mode 100644 index 0000000..7270047 --- /dev/null +++ b/disk_cleanup_linux @@ -0,0 +1,38 @@ +#!/bin/bash + +echo "Starting Linux disk cleanup..." + +# Clean package cache (for systems using APT) +if command -v apt-get &> /dev/null; then + echo "Cleaning package cache..." + sudo apt-get clean + sudo apt-get autoclean + sudo apt-get autoremove -y +fi + +# Clean YUM package cache (for RHEL/CentOS systems) +if command -v yum &> /dev/null; then + echo "Cleaning YUM package cache..." + sudo yum clean all +fi + +# Remove old system logs +echo "Removing old system logs..." +sudo find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; + +# Clean temporary directories +echo "Cleaning temporary directories..." +sudo rm -rf /tmp/* +sudo rm -rf /var/tmp/* + +# Remove old kernels (keep the current and one previous) +if command -v dpkg &> /dev/null; then + echo "Removing old kernels..." + sudo dpkg-query -l 'linux-image*' | awk '{ print $2 }' | grep -E 'linux-image-[0-9]+' | grep -v "$(uname -r)" | xargs sudo apt-get -y purge +fi + +# Clean thumbnail cache +echo "Cleaning thumbnail cache..." +rm -rf ~/.cache/thumbnails/* + +echo "Disk cleanup completed."