du 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-du
핵심 정리
- 파일과 디렉터리가 쓰는 블록 수를 보여 줍니다. 기본 단위는 512바이트 블록이며,
-k(KB),-m(MB),-g(GB)로 바꿉니다. - 디렉터리를 주면 그 디렉터리와 모든 하위 디렉터리마다 합계를 보여 줍니다.
-s는 준 것마다 합계 한 줄만,-a는 파일마다 보여 줍니다. - 자주 쓰는 형태:
du -sg /var,du -sk * | sort -n | tail(가장 큰 항목),du -xm /(다른 파일 시스템은 빼고). - 하드 링크가 여럿인 파일은 한 번만 셉니다.
-x는 같은 장치(파일 시스템)의 파일만 셉니다. df의 사용량과du합계가 다르면, 지웠지만 아직 열려 있는 파일이 공간을 붙잡고 있을 수 있습니다(fuser -dV 파일시스템으로 확인).
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 JFS2 스냅숏 안의 객체에 대한 설명과 -H·-L을 함께 줄 때의 참고가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2 |
| 파일 | /usr/bin/du |
| 관련 명령어 | df, ls -l, find -size |
목적
디스크 사용량을 요약합니다.
영어 원문
Summarizes disk usage.
구문
du [ -a | -s ] [ -k ] [ -m ] [ -g ] [ -l ] [ -r ] [ -x ] [ -H | -L ] [ File ... ]
설명
du 명령은 파일이 쓰는 블록 수를 보여 줍니다. File이 디렉터리면 그 안의 모든 파일을 보고하고, File을 주지 않으면 현재 디렉터리의 파일을 씁니다.
File이 디렉터리면 보고하는 블록 수는 그 안의 파일에 할당된 블록과 디렉터리 자체에 할당된 블록의 합입니다.
(6.1) JFS2 스냅숏 안의 파일이나 디렉터리면 스냅숏을 만든 시점의 객체 정보를 보여 줍니다. 스냅숏을 지우면 되찾을 공간은 포함하지 않습니다.
-a는 파일마다 블록 수를 보고합니다. -a와 상관없이 File로 준 파일은 늘 나열합니다. -s는 지정한 모든 파일이나 디렉터리 안의 모든 파일의 합계를 보고합니다.
블록 수에는 파일마다의 간접 블록이 포함되며, 시스템의 클러스터 크기와 상관없이 512바이트 단위로 셉니다. -k는 1024바이트 단위로 셉니다.
참고:
- 링크가 여럿인 파일은 한 항목만 세고 씁니다.
- 블록 수는 파일 크기만으로 정하므로, 할당이 풀린 블록은 세지 않습니다.
- 파일 속성을 얻거나 디렉터리를 읽을 수 없으면 오류를 알리고 종료 상태에 반영합니다.
영어 원문
The du command displays the number of blocks used for files. If the File parameter specified is actually a directory, all files within the directory are reported on. If no File parameter is provided, the du command uses the files in the current directory.
If the File parameter is a directory, then the number of blocks reported is the sum of blocks allocated for the files in the directory and the blocks allocated for the directory itself.
If the object of the du command is a file or directory that exists inside a JFS2 snapshot, the du command gives information for the point-in-time object when the snapshot is created. This information does not include how much space is recovered if the snapshot itself is deleted.
Specifying the -a flag reports the number of blocks in individual files. Whether the -a flag is used or not, individual files specified by the File parameter are always listed.
Specifying the -s flag reports the total blocks for all specified files or all files in a directory.
The block count includes indirect blocks of each file. Block count is calculated in 512-byte units independent of the cluster size used by the system. Specifying the -k flag calculates the block count in 1024-byte units.
Notes:
Files with multiple links are counted and written for only one entry.
Block counts are based only on file size; therefore, deallocated blocks are not accounted for in the reported block counts.
If du cannot obtain the file attributes or cannot read directories, it reports an error and the exit status of the command is affected.
플래그
| 플래그 | 설명 |
|---|---|
-a |
준 파일마다, 준 디렉터리 안(하위 디렉터리 포함)의 파일마다 사용량을 보여 줍니다. -s와 반대입니다. |
-g |
GB 단위로 셉니다. 값은 소수로 나옵니다. |
-H |
명령줄에 준 심볼릭 링크가 가리키는 파일이나 계층의 크기를 셉니다. |
-k |
1024바이트 단위로 셉니다. |
-l |
링크가 여럿인 파일의 블록을 링크마다 고르게 나눕니다. 기본은 한 번만 셉니다. |
-L |
명령줄에 준 것이나 순회 중 만난 심볼릭 링크가 가리키는 파일이나 계층의 크기를 셉니다. |
-m |
MB 단위로 셉니다. 값은 소수로 나옵니다. |
-r |
접근할 수 없는 파일과 디렉터리 이름을 보고합니다(기본). |
-s |
준 파일마다, 준 디렉터리마다 그 안(하위 디렉터리 포함) 전체의 합계를 보여 줍니다. -a와 반대입니다. |
-x |
File로 준 파일이나 디렉터리와 같은 장치에 있는 파일만 셉니다. 여러 장치의 파일이 섞인 디렉터리에서 그 디렉터리의 장치에 있는 것만 보여 줍니다. |
참고:
-k,-m,-g를 둘 이상 주면 마지막 것을 따르며,-m,-g의 값은 소수 둘째 자리로 반올림합니다.- 서로 배타적인
-H와-L을 함께 줘도 오류는 나지 않고 마지막 것을 따릅니다.
영어 원문
-a— For each file specified, displays the disk usage of the file. For each directory specified, displays the disk usage of each individual file within the directory, including all subdirectories. Contrast this flag with the-sflag.-g— Calculates the block count in GB units rather than the default 512-byte units. The output values for the disk usage would be in floating point numbers as value of each unit in bytes is significantly high.-H— If a symbolic link is specified on the command line, the du command shall count the size of the file or file hierarchy referenced by the link.-k— Calculates the block count in 1024-byte units rather than the default 512-byte units.-l— Allocates blocks evenly among the links for files with multiple links. By default, a file with two or more links is counted only once.-L— If a symbolic link is specified on the command line or encountered during the traversal of a file hierarchy, the du command shall count the size of the file or file hierarchy referenced by the link.-m— Calculates the block count in MB units rather than the default 512-byte units. The output values for the disk usage would be in floating point numbers as value of each unit in bytes is significantly high.-r— Reports names of inaccessible files and directories. This is the default.-s— For each file specified, displays the disk usage of the file. For each directory specified, displays the total disk usage of all files within the directory, including all subdirectories. Contrast this flag with the-aflag.-x— When evaluating file sizes, evaluates only those files that reside on the same device as the file or directory specified by the File parameter. For example, you may specify a directory that contains files on several devices. In this case, the-xflag displays block sizes for all files that reside on the same device as the directory.- Notes:
If all or any two of the
-k,-mand-gflags are specified, the last one specified takes effect. The output of the disk usage with the flags-mand-gwould be rounded off to the nearest second decimal digit.If both the mutually exclusive options
-Hand-Lare specified simultaneously, the command does not report an error. The last specified option determines the behavior of the utility.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 성공 |
| 0보다 큼 | 오류 |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
예제
| 명령 | 하는 일 |
|---|---|
du /home/fran |
/home/fran과 각 하위 디렉터리의 블록 수 |
du -k /home/fran |
같은 내용을 1024바이트 블록으로 |
du -m /home/fran |
MB 단위(소수 둘째 자리) |
du -g /home/fran |
GB 단위(소수 둘째 자리) |
du -a /home/fran |
파일과 하위 디렉터리마다. 디렉터리 옆 숫자는 그 트리 전체, 파일 옆 숫자는 그 파일만 |
du -s /home/fran |
/home/fran 전체 합계만. 읽을 수 없는 파일이 있으면 기본으로 오류 메시지를 냄 |
du -L /home/fran |
순회 중 만난 모든 심볼릭 링크가 가리키는 대상까지 셈 |
du -H mylink |
심볼릭 링크 mylink가 가리키는 대상의 사용량 |
자주 쓰는 형태:
du -sm /var/* | sort -n | tail -10 # /var 아래 큰 디렉터리
du -xk / | sort -n | tail -20 # / 파일 시스템 안에서만
find /var -xdev -size +200000 -ls # 100MB(512바이트 × 200000)보다 큰 파일
fuser -dV /var # 지웠지만 열려 있는 파일
영어 원문
- To summarize the disk usage of a directory tree and each of its subtrees, enter:
du /home/fran
This displays the number of disk blocks in the /home/fran directory and each of its subdirectories.
- To summarize the disk usage of a directory tree and each of its subtrees in 1024-byte blocks, enter:
du -k /home/fran
This displays the number of 1024-byte disk blocks in the /home/fran directory and each of its subdirectories.
- To summarize the disk usage of a directory tree and each of its subtrees in MB blocks, enter:
du -m /home/fran
This displays the number of MB disk blocks rounded off to nearest 2nd decimal digit in the /home/fran directory and each of its subdirectories.
- To summarize the disk usage of a directory tree and each of its subtrees in GB blocks, enter:
du -g /home/fran
This displays the number of GB disk blocks rounded off to nearest 2nd decimal digit in the /home/fran directory and each of its subdirectories.
- To display the disk usage of each file, enter:
du -a /home/fran
This displays the number of disk blocks contained in each file and subdirectory of the /home/fran directory. The number beside a directory is the disk usage of that directory tree. The number beside a regular file is the disk usage of that file alone.
- To display only the total disk usage of a directory tree, enter:
du -s /home/fran
The -s flag instructs the du command to display only the sum total disk usage of the /home/fran directory and the files it contains. By default, the du command displays an error message if it cannot read a file or directory.
To display the disk usage of the files and file hierarchies referenced by all the symbolic links in addition to the normal files found during traversal of a the
/home/frandirectory, type:du -L /home/franTo report the disk usage of the file or file hierarchy referenced by the symbolic link
mylink, type:du -H mylink
파일
| 파일 | 설명 |
|---|---|
/usr/bin/du |
du 명령 |
영어 원문
- /usr/bin/du — Contains the du command.
Related reference:
- df Command
Related information:
- Directories command
- Files command
리눅스(GNU)와 다른 점
리눅스 GNU du는 기본 단위가 1KB이고 -h(사람이 읽기 쉬운 단위), --max-depth=N(-d N), -c(총합)가 있습니다. AIX du에는 -h와 깊이 제한이 없어 du -sk *와 sort를 함께 씁니다.