disk-maintenance 687 B

123456789101112131415161718192021
  1. #!/bin/bash
  2. # search and destroy garbage files in root
  3. find / -type f -iname "thumbs.db" -exec rm {} \; 2> /dev/null &
  4. find / -type f -iname ".ds_store" -exec rm {} \; 2> /dev/null &
  5. find / -type f -name '._*' -exec rm -rf {} \; 2> /dev/null &
  6. # fstrim and defragment ext4
  7. for filesystem in $(mount -t ext4 | awk '{print $3}'); do
  8. fstrim "$filesystem"
  9. e4defrag "$filesystem"
  10. done
  11. # rebalance and trim SSD btrfs (HDD are too slow and should be done manually)
  12. for filesystem in $(mount -t btrfs | grep "ssd" | awk '{print $3}'); do
  13. btrfs balance start -musage=11 dusage=10 "$filesystem"
  14. fstrim "$filesystem"
  15. done
  16. # cleanup journalctl
  17. journalctl --vacuum-time=5d --vacuum-size=500M