delete_temp_files 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. ####
  3. # For use in WSL
  4. # Deletes stale temp files from AppData and my downloads folder
  5. ####
  6. WIN_USER="$(wslpath "$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)")"
  7. LOCAL="$WIN_USER/AppData/Local/Temp"
  8. DOWNLOADS="$WIN_USER/Downloads/Temporary"
  9. cd "$LOCAL"
  10. echo "Deleting SSH agents"
  11. find ./ssh-* -maxdepth 1 -type d -mtime +1 2>/dev/null | while IFS= read -r dir
  12. do
  13. rm -r "$dir"
  14. done
  15. echo "Deleting Office temp files"
  16. find ./TCD* -maxdepth 1 -type d -mtime +5 2>/dev/null | while IFS= read -r dir
  17. do
  18. rm -r "$dir"
  19. done
  20. echo "Deleting MySQL Workbench files"
  21. find ./mysql-workbench-* -maxdepth 1 -type d -mtime +1 2>/dev/null | while IFS= read -r dir
  22. do
  23. rm -r "$dir"
  24. done
  25. echo "Deleting Google Chrome temp files"
  26. find ./chrome_drag* -maxdepth 1 -type d -mtime +2 2>/dev/null | while IFS= read -r dir
  27. do
  28. rm -r "$dir"
  29. done
  30. echo "Deleting all other *.tmp files"
  31. find ./*.tmp -maxdepth 1 -type f -mtime +2 -delete 2>/dev/null
  32. echo "Deleting month-old temporary downloads"
  33. cd "$DOWNLOADS"
  34. find ./* -maxdepth 1 -type f -mtime +30 -delete 2>/dev/null
  35. cd "$OLDPWD"