Add disk_cleanup_linux
This commit is contained in:
parent
3f2c695605
commit
b1d5e2665f
38
disk_cleanup_linux
Normal file
38
disk_cleanup_linux
Normal file
@ -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."
|
||||||
Loading…
x
Reference in New Issue
Block a user