리눅스 디스크 정리

공부는 혼자하는 거·2025년 6월 29일
0

환경

목록 보기
30/30

배포했는데 실패 원인 까보니 역시 디스크 용량 부족..


# 디스크 확인
df -h

# 100MB 이상 파일 찾기 (실행 전 꼭 확인!)
sudo find / -type f -size +100M 2>/dev/null | xargs ls -lh


# Docker 정리 (사용 중인 도커가 있다면)
docker system prune -f

# 패키지 관리자 캐시 정리
sudo apt-get clean  # Ubuntu/Debian
sudo yum clean all  # CentOS/RHEL

# 로그 파일 정리
sudo journalctl --vacuum-size=200M
sudo rm -f /var/log/*.log.*

아예 스크립트 파일로 하나 만들어서 크론에 등록

sudo vi /usr/local/bin/disk-cleanup.sh # 파일 생성
#!/bin/bash

# Docker 정리
docker system prune -f

# 패키지 캐시 정리
apt-get clean

# 로그 정리
journalctl --vacuum-size=200M
find /var/log -name "*.log.*" -mtime +7 -delete


# 임시 파일 정리
rm -rf /tmp/*
~

권한

sudo chmod +x /usr/local/bin/disk-cleanup.sh

실행

(crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/disk-cleanup.sh") | crontab -

내 도커 컴포즈 파일 수정

version: '3.8'
services:
  myapp:
    image: myapp:latest
    logging:
      driver: "json-file"
      options:
        max-size: "10k"
        max-file: "3"
profile
시간대비효율

0개의 댓글