delete_temp_files 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. WIN_USER="$(wslpath "$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)")"
  3. LOCAL="$WIN_USER/AppData/Local/Temp"
  4. ROAMING="$WIN_USER/AppData/Roaming"
  5. DOWNLOADS="$WIN_USER/Downloads/Temporary"
  6. cd "$LOCAL"
  7. echo "Deleting SSH agents"
  8. find ./ssh-* -maxdepth 1 -type d -mtime +1 2>/dev/null | while IFS= read -r dir
  9. do
  10. rm -r "$dir"
  11. done
  12. echo "Deleting Office temp files"
  13. find ./TCD* -maxdepth 1 -type d -mtime +5 2>/dev/null | while IFS= read -r dir
  14. do
  15. rm -r "$dir"
  16. done
  17. echo "Deleting MySQL Workbench files"
  18. find ./mysql-workbench-* -maxdepth 1 -type d -mtime +1 2>/dev/null | while IFS= read -r dir
  19. do
  20. rm -r "$dir"
  21. done
  22. echo "Deleting Google Chrome temp files"
  23. find ./chrome_drag* -maxdepth 1 -type d -mtime +2 2>/dev/null | while IFS= read -r dir
  24. do
  25. rm -r "$dir"
  26. done
  27. echo "Deleting go-build temp files"
  28. find ./go-build* -maxdepth 1 -type d -mtime +5 2>/dev/null | while IFS= read -r dir
  29. do
  30. rm -r "$dir" 2>/dev/null
  31. done
  32. echo "Deleting NodeJS Yarn temp files"
  33. find ./yarn--* -maxdepth 1 -type d -mtime +2 2>/dev/null | while IFS= read -r dir
  34. do
  35. rm -r "$dir"
  36. done
  37. echo "Deleting all other *.tmp files"
  38. find ./*.tmp -maxdepth 1 -mtime +2 -delete 2>/dev/null
  39. find -regextype posix-extended -regex "^\.\/\{[0-9A-F\-]{36}\}" -mtime +7 -delete 2>/dev/null
  40. echo "Deleting month-old temporary downloads"
  41. cd "$DOWNLOADS"
  42. find ./* -maxdepth 1 -mtime +30 -delete 2>/dev/null
  43. cd "$ROAMING"
  44. echo "Deleting VS Code caches older than 30 days"
  45. find ./Code/Cache/Cache_Data/* -type f -mtime +30 2>/dev/null | while IFS= read -r file
  46. do
  47. rm -f "$file"
  48. done
  49. find ./Code/CachedData/ -maxdepth 1 -type d -mtime +30 2>/dev/null | while IFS= read -r dir
  50. do
  51. rm -rf "$dir"
  52. done
  53. echo "Deleting DBeaver files"
  54. find ./DBeaverData/workspace6/General/Scripts/*.sql -size +1c -atime +7 -delete 2>/dev/null
  55. cd "$OLDPWD"