2026년 4월 23일 목요일

개발자 도구 캐시 정리 및 용량 줄이는 방법

이 글은 개발자 도구 캐시 정리 및 용량 줄이는 방법을 간략히 나눔한다. 

기본적으로 허깅페이스, PIP 등을 사용하는 개발자로 가정한다.

명령창을 띄워 다음과 같이 실행한다. 
pip cache purge
conda clean --all -y
huggingface-cli delete-cache
wandb sync --clean
npm cache clean --force
yarn cache clean
pnpm store prune
docker system prune -a --volumes
docker builder prune -a
docker image prune -a

파이썬에서 다음을 실행한다.
import torch
torch.cuda.empty_cache()

임시 폴더를 삭제한다.
C:\Windows\Temp\
C:\Windows\SoftwareDistribution\Download\

도커 이미지 모두 삭제하려면 다음 실행한다.
docker rmi -f $(docker images -q)

다음과 같이 배치파일을 작성해 한번에 처리할 수도 있다.

@echo off
chcp 65001 >nul
cls

:: 1. 개발 패키지 및 AI 캐시 정리
where pip >nul 2>&1 && echo [*] pip cache... && pip cache purge >nul 2>&1
where conda >nul 2>&1 && echo [*] conda cache... && call conda clean --all --yes >nul 2>&1
where npm >nul 2>&1 && echo [*] npm cache... && call npm cache clean --force >nul 2>&1

where huggingface-cli >nul 2>&1 && echo [*] Hugging Face cli cache... && huggingface-cli delete-cache --quiet >nul 2>&1
if exist "C:\Users\KSW\.cache\huggingface\hub" (
    echo [*] Cleaning Hugging Face incomplete downloads...
    del /f /s /q "C:\Users\KSW\.cache\huggingface\hub\version.txt" >nul 2>&1
)

:: 2. 도커(Docker) 캐시 및 끊어진 이미지 정리 
where docker >nul 2>&1 && echo [*] Docker system pruning... && docker system prune -f >nul 2>&1

:: 3. 임시 폴더(Temp) 파일 정리
echo [*] Cleaning Temp folders...
if exist "C:\Users\KSW\AppData\Local\Temp" (
    del /f /s /q "C:\Users\KSW\AppData\Local\Temp\*.*" >nul 2>&1
    for /d %%p in ("C:\Users\KSW\AppData\Local\Temp\*") do rmdir /s /q "%%p" >nul 2>&1
)
if exist "%SystemRoot%\Temp" (
    del /f /s /q "%SystemRoot%\Temp\*.*" >nul 2>&1
    for /d %%p in ("%SystemRoot%\Temp\*") do rmdir /s /q "%%p" >nul 2>&1
)
if exist "%SystemRoot%\Prefetch" (
    del /f /s /q "%SystemRoot%\Prefetch\*.*" >nul 2>&1
)

echo [+] All caches cleared.
timeout /t 3

댓글 없음:

댓글 쓰기