Просмотр исходного кода

Add several new directories to delete list

This script now checks for an deletes:
go-build folders
NodeJS Yarn cache folders
*.tmp files AND directories
UUID folders
VS Code cache folders
ApisNecros 2 лет назад
Родитель
Сommit
d2b4647d4f
1 измененных файлов с 29 добавлено и 6 удалено
  1. 29 6
      delete_temp_files

+ 29 - 6
delete_temp_files

@@ -1,12 +1,8 @@
 #!/bin/bash
 
-####
-# For use in WSL
-# Deletes stale temp files from AppData and my downloads folder
-####
-
 WIN_USER="$(wslpath "$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)")"
 LOCAL="$WIN_USER/AppData/Local/Temp"
+ROAMING="$WIN_USER/AppData/Roaming"
 DOWNLOADS="$WIN_USER/Downloads/Temporary"
 
 cd "$LOCAL"
@@ -38,13 +34,40 @@ do
 	rm -r "$dir"
 done
 
+echo "Deleting go-build temp files"
+
+find ./go-build* -maxdepth 1 -type d -mtime +5 2>/dev/null | while IFS= read -r dir
+do
+	rm -r "$dir" 2>/dev/null
+done
+
+echo "Deleting NodeJS Yarn temp files"
+
+find ./yarn--* -maxdepth 1 -type d -mtime +2 2>/dev/null | while IFS= read -r dir
+do
+	rm -r "$dir"
+done
+
 echo "Deleting all other *.tmp files"
 
-find ./*.tmp -maxdepth 1 -type f -mtime +2 -delete 2>/dev/null 
+find ./*.tmp -maxdepth 1 -mtime +2 -delete 2>/dev/null 
+find -regextype posix-extended -regex "^\.\/\{[0-9A-F\-]{36}\}" -mtime +7 -delete 2>/dev/null
 
 echo "Deleting month-old temporary downloads"
 
 cd "$DOWNLOADS"
 find ./* -maxdepth 1 -type f -mtime +30 -delete 2>/dev/null
 
+cd "$ROAMING"
+echo "Deleting VS Code caches older than 30 days"
+
+find ./Code/Cache/Cache_Data/* -type f -mtime +30 2>/dev/null | while IFS= read -r file
+do
+	rm -f "$file"
+done
+find ./Code/CachedData/ -maxdepth 1 -type d -mtime +30 2>/dev/null | while IFS= read -r dir
+do
+	rm -rf "$dir"
+done
+
 cd "$OLDPWD"