SE업무/OS

리눅스 , 윈도우 용량 큰 파일 찾기

에륜 2021. 6. 11. 17:05
반응형

디스크가 꽉차서 서버 에러가 날때가 생각보다 있다.

그래서 모든 시스템 디스크 알람은 필수이다.

 

디스크 용량 초과 알람이 발생해서 서버를 접속하게된다면

내가 구축하고 자주 접속하는 서버라면 당연히 파일이 주로 쌓이는 로그파일이나

큰 파일을 찾아서 삭제하겠지만

처음 접속하는 서버의 경우 로그 경로도 모르고 모든게 생소하다..

 

1.리눅스

 

리눅스의 경우 du 명령어로 주로 탐색한다.

아래는 du 명령어 옵션과 설명이다.

[root@infra-01 /]# du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with 0 byte rather than newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize disk usage of the
                          NUL-terminated file names specified in file F;
                          if F is -, then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes          list inode usage information instead of block usage
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   for directories do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using STYLE, which can be:
                            full-iso, long-iso, iso, or +FORMAT;
                            FORMAT is interpreted like in 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

du를 입력하는 순간

현재 경로의 모든 하위폴더의 용량을 보여준다.

용량 큰파일을 찾기위해서 / 에서 명령어 날리면 엄청나게 많은 양이 정리되지 않은채 나온다.

일단 보기 편하게 하는 옵션은 h와 s이다.

h는 읽기쉽게 단위를 변경해주고 s는 요약해서 현재 폴더의 크기를 알려준다.

하지만 이것도 하위의 하위 경로가 나와 정보량이 너무 많다..

(사진은 테스트 서버에서 한것이고 실제 서비스중인 서버에서 루트에서 한다면 엄청나게 나올수도있다.)

해당 폴더에 보이는 폴더들의 크기만 알려고한다면

du -h *

숨은 폴더도 보고싶다면

du -h --max-depth=1을 하면된다.

 

이제 정렬만 하면되는데 정렬은 sort 명령어를 사용하면된다.

sort 잘되는것을 보여주기위해  --max-depth=1로 확인하였다.

 

sort 옵션에 역순옵션인 r을 쓰고 안쓰고에 따라 정렬 순이 달라진다.

나는 주로 r을 안쓰고 최대값이 아래로 보이게하면서 쓰는 스타일이다.

 

서버가 관리서버이거나 영향도가 낮다면 아래와 같이

루트에서 du -h | sort -h 명령어를 날리면 빨리 찾을수 있지만 혹시 모르니 주의하자..

 

2. 윈도우에서 용량 큰 폴더 찾기

 

이 방법은 프로그램을 사용하도록하자.

윈도우의 장점은 GUI와 다양한 프로그램이 존재하다는 것이다.

좋은건 쓰는게 편하다..

특히 윈도우는 로컬 어드민 계정이 아닌 일반계정으로 접근시 권한에 따라 안보이는 폴더 및 파일이 많다.

 

SpaceSniffer라는 프로그램을 추천한다.

장점은 보기편하고 설치필요 없이 포터블이 가능하다.

 

http://www.uderzo.it/main_products/space_sniffer/download.html

 

SpaceSniffer download

 

www.uderzo.it

 

다운 받아서 압축풀면 바로 사용가능이다.

실행시 관리자권한으로 실행하자.

 

실행시 디스크를 선택하면 해당 디스크 정보를 수집하여 용량을 아래와 같이 바로 보여준다.

폴더의 크기에 따라 보여주기때문에 한눈에 확보인다.

해당 이미지를 클릭하면(킹든갓택을 클릭했다)

이렇게 해당 폴더내에서 다시 계산하여서 보여준다.

 

삭제를 위해 직접 접근을 하고싶다면 우클릭을 하면 바로 폴더 열기가 가능하다. 주의점은 폴더가 아닌

실행파일을 열기할경우 실행되니(파란색 부분) 꼭 주황색 상단에서 우클릭하길 추천한다.

 

 

큰 파일을 찾았다고해서 바로 삭제하는게 아니라 영향도 없을지 판단 한후 삭제해야합니다~

 

다들 빠르게 트러블슈팅하시길 기원합니다.

반응형