40 lines
1.2 KiB
Bash
40 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# wget -O /tmp/disk_cleanup.sh https://git.technozone.com.au/vijay/Scripts/raw/branch/main/disk_cleanup && bash /tmp/disk_cleanup.sh && rm -f /tmp/disk_cleanup.sh
|
|
|
|
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."
|