리눅스 명령어 / du
du 명령어
du는 disk usage의 약자로 디렉토리(폴더)와 파일의 용량을 출력해주는 명령어입니다.
예제
dataroom 디렉토리 안에 10MB.FILE이, dataroom/aaa 디렉토리 안에 20MB.FILE이, dataroom/aaa/bbb 디렉토리 안에 30MB.FILE이 있다고 가정하겠습니다. 파일 크기는 파일명대로 각각 10MB, 20MB, 30MB입니다.
# tree
.
└── dataroom
├── 10MB.FILE
└── aaa
├── 20MB.FILE
└── bbb
└── 30MB.FILE
파일 크기 확인
du 명령어 뒤에 파일명을 넣으면 해당 파일의 크기를 출력합니다. 단위는 kbyte입니다.
# du dataroom/10MB.FILE
10240 dataroom/10MB.FILE
읽기 편한 단위로 출력하고 싶다면 h 옵션을 붙입니다.
# du -h dataroom/10MB.FILE
10M dataroom/10MB.FILE
디렉토리 사용량 확인
du 명령어 뒤에 디렉토리명을 넣으면 해당 디렉토리와 하위 디렉토리의 사용량이 출력됩니다.
# du dataroom
30720 dataroom/aaa/bbb
51200 dataroom/aaa
61440 dataroom
# du -h dataroom
30M dataroom/aaa/bbb
50M dataroom/aaa
60M dataroom
특정 디렉토리만의 사용량을 출력하고 싶다면 s 옵션을 붙입니다.
# du -s dataroom
61440 dataroom
# du -sh dataroom
60M dataroom
d 옵션으로 몇 단계 하위 디렉토리까지 출력할지 정할 수 있습니다. 다음과 같이 명령하면 dataroom 디렉토리의 1단계 하위 디렉토리까지의 사용량을 출력합니다.
# du -d 1 dataroom
51200 dataroom/aaa
61440 dataroom
# du -hd 1 dataroom
50M dataroom/aaa
60M dataroom
a 옵션을 붙이면 디렉토리에 속한 파일의 크기도 같이 출력합니다.
# du -a dataroom
30720 dataroom/aaa/bbb/30MB.FILE
30720 dataroom/aaa/bbb
20480 dataroom/aaa/20MB.FILE
51200 dataroom/aaa
10240 dataroom/10MB.FILE
61440 dataroom
# du -ah dataroom
30M dataroom/aaa/bbb/30MB.FILE
30M dataroom/aaa/bbb
20M dataroom/aaa/20MB.FILE
50M dataroom/aaa
10M dataroom/10MB.FILE
60M dataroom