본문 바로가기
Development/리눅스

리눅스 df, du 파일 시스템 디스크 사용량 측정 명령어 사용 방법

by 버들도령 2024. 3. 14.
728x90

Linux에서는 df 명령을 사용하여 디스크 공간 사용량을 추정하고 du 명령을 사용하여 파일 공간 사용량을 추정합니다. 이 기사에서는 df와 du 명령의 차이점과 각 명령을 사용하는 경우에 대해 알아봅니다. df 및 du 명령은 거의 모든 Linux 배포판에서 사용할 수 있습니다.

df (Disk Free)와 du (Disk Usage) 명령의 차이점

du (디스크 사용량, Disk Usage) 명령은 Linux에서 파일 시스템의 파일 및 폴더가 차지하는 공간을 가져오는 데 사용되며, df (디스크 여유 공간, Disk Free) 명령은 사용자가 액세스할 수 있는 파일 시스템의 여유 디스크 공간을 표시하는 데 사용됩니다. du 명령은 일반적으로 특히 디스크 공간을 확보하려는 경우 시스템에서 가장 큰 폴더를 찾는 데 사용됩니다. du 명령은 단순히 디스크 사용량(사용 가능한 디스크 공간 및 사용된 디스크 공간)을 모니터링하는 데 사용됩니다.

  • du (Disk Usage) : 디렉토리별로 디스크 사용량을 표시
  • df (Disk Free) : 파일 시스템 메타데이터의 디스크 블록을 사용하여 필요한 수를 계산

df (Disk Free)

df는 각 파일 이름 인수를 포함하는 파일 시스템에서 사용 가능한 디스크 공간의 양을 표시합니다.

파일 이름을 지정하지 않으면 현재 마운트된 모든 파일 시스템에서 사용 가능한 공간이 표시됩니다.
POSIXLY_CORRECT 환경 변수가 설정되지 않은 경우 디스크 공간은 기본적으로 1K 블록으로 표시되며 이 경우 512바이트 블록이 사용됩니다.

인수가 마운트된 파일 시스템을 포함하는 디스크 장치 노드의 절대 파일 이름인 경우 df는 장치 노드를 포함하는 파일 시스템(항상 루트 파일 시스템임)이 아닌 해당 파일 시스템에서 사용 가능한 공간을 표시합니다. 이 버전의 df는 마운트되지 않은 파일 시스템에서 사용 가능한 공간을 표시할 수 없습니다. 
대부분의 시스템에서 그렇게 하려면 파일 시스템 구조에 대한 매우 이식하기 어려운 친밀한 지식이 필요하기 때문입니다.

[invusomuch@server]$ df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -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
      --direct          show statistics for a file instead of mount point
  -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
  -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
      --total           elide all entries insignificant to available space,
                          and produce a grand total
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --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 DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

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

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'
[invusomuch@server]$ man df
DF(1)                                                                                      User Commands                                                                                     DF(1)

NAME
       df - report file system disk space usage

SYNOPSIS
       df [OPTION]... [FILE]...

DESCRIPTION
       This  manual  page  documents  the GNU version of df.  df displays the amount of disk space available on the file system containing each file name argument.  If no file name is given, the
       space available on all currently mounted file systems is shown.  Disk space is shown in 1K blocks by default, unless the  environment  variable  POSIXLY_CORRECT  is  set,  in  which  case
       512-byte blocks are used.

       If an argument is the absolute file name of a disk device node containing a mounted file system, df shows the space available on that file system rather than on the file system containing
       the device node.  This version of df cannot show the space available on unmounted file systems, because on most kinds of systems doing so requires very nonportable intimate  knowledge  of
       file system structures.

OPTIONS
       Show information about the file system on which each FILE resides, or all file systems by default.

       Mandatory arguments to long options are mandatory for short options too.

       -a, --all
              include pseudo, duplicate, inaccessible file systems

       -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

       --direct
              show statistics for a file instead of mount point

       -h, --human-readable
              print sizes in powers of 1024 (e.g., 1023M)

       -H, --si
              print sizes in powers of 1000 (e.g., 1.1G)

       -i, --inodes
              list inode information instead of block usage

       -k     like --block-size=1K

       -l, --local
              limit listing to local file systems

       --no-sync
              do not invoke sync before getting usage info (default)

       --output[=FIELD_LIST]
              use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

       -P, --portability
              use the POSIX output format

       --sync invoke sync before getting usage info

       --total
              elide all entries insignificant to available space, and produce a grand total

       -t, --type=TYPE
              limit listing to file systems of type TYPE

       -T, --print-type
              print file system type

       -x, --exclude-type=TYPE
              limit listing to file systems not of type TYPE

       -v     (ignored)

       --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 DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.  Otherwise, units default to 1024 bytes
       (or 512 if POSIXLY_CORRECT is set).

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

       FIELD_LIST is a comma-separated list of columns to be included.  Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent', 'file'
       and 'target' (see info page).

AUTHOR
       Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report df translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright ⓒ 2018 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       Full documentation at: <https://www.gnu.org/software/coreutils/df>
       or available locally via: info '(coreutils) df invocation'

GNU coreutils 8.30                                                                           July 2018

 

[invusomuch@server]$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         3955964       0   3955964   0% /dev
tmpfs            3974828      12   3974816   1% /dev/shm
tmpfs            3974828     584   3974244   1% /run
tmpfs            3974828       0   3974828   0% /sys/fs/cgroup
/dev/sda2       41922560 4531304  37391256  11% /
/dev/sda5      110568708 1957732 108610976   2% /home
/dev/sda1         518816  179044    339772  35% /boot
tmpfs             794964       0    794964   0% /run/user/500
tmpfs             794964       0    794964   0% /run/user/11000

 

 

du (Disk Usage)

디렉토리와 하위 디렉토리에 대한 각 파일의 디스크 사용을 표시합니다.

[invusomuch@server]$ du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of the set of FILEs, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not 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).

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

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/du>
or available locally via: info '(coreutils) du invocation'
[invusomuch@server]$ man du
DU(1)                                                                                   User Commands                                                                                  DU(1)

NAME
       du - estimate file space usage

SYNOPSIS
       du [OPTION]... [FILE]...
       du [OPTION]... --files0-from=F

DESCRIPTION
       Summarize disk usage of the set of FILEs, recursively for directories.

       Mandatory arguments to long options are mandatory for short options too.

       -0, --null
              end each output line with NUL, not 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, indi?
              rect 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).

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

PATTERNS
       PATTERN  is  a  shell pattern (not a regular expression).  The pattern ? matches any one character, whereas * matches any string (composed of zero, one or multiple characters).  For
       example, *.o will match any files whose names end in .o.  Therefore, the command

              du --exclude='*.o'

       will skip all files and subdirectories ending in .o (including the file .o itself).

AUTHOR
       Written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report du translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright ⓒ 2018 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       Full documentation at: <https://www.gnu.org/software/coreutils/du>
       or available locally via: info '(coreutils) du invocation'

GNU coreutils 8.30                                                                        July 2018
  • du /home/user/Desktop : 이 명령줄을 사용하면 사용자가 데스크탑 폴더 및 파일의 디스크 사용량을 볼 수 있습니다(하위 디렉토리도 포함됨).
  • du -h /home/user/Desktop : df 와 마찬가지로 -h 옵션은 사람이 읽을 수 있는 형식으로 정보를 표시 합니다.
  • du -sh /home/user/Desktop :  -s  옵션은 지정된 폴더(이 경우 Desktop)의 총 크기를 제공합니다.
  • du -m /home/user/Desktop : -m 옵션은 Mega bytes 단위로 폴더 및 파일 크기를 제공합니다 ( -k 를 사용 하여 Kilo bytes 단위 로 정보를 볼 수 있음).
  • du -h : time /home/user/Desktop — 표시된 폴더 및 파일의 마지막 수정 날짜를 알려줍니다.
  • df –help : 사용 가능한 옵션 목록과 용도를 표시합니다.

 

[root@invusomuch-WAS01 ~]# du
148     ./.pulse
16      ./.gnupg
20      ./.ssh
8       ./.dbus/session-bus
12      ./.dbus
4       ./.nautilus
8       ./.cache/gedit
24      ./.cache
4       ./.thumbnails/normal
8       ./.thumbnails
52      ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/global
172     ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5/projects/org.sonarqube%3Ajava-simple-sq-scanner
176     ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5/projects
180     ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5
236     ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000
240     ./.sonar/ws_cache
....

 

[root@invusomuch-WAS01 ~]# du -h
148K    ./.pulse
16K     ./.gnupg
20K     ./.ssh
8.0K    ./.dbus/session-bus
12K     ./.dbus
4.0K    ./.nautilus
8.0K    ./.cache/gedit
24K     ./.cache
4.0K    ./.thumbnails/normal
8.0K    ./.thumbnails
52K     ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/global
172K    ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5/projects/org.sonarqube%3Ajava-simple-sq-scanner
176K    ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5/projects
180K    ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/5.5
236K    ./.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000
240K    ./.sonar/ws_cache
....

 

[root@invusomuch-WAS01 ~]# du -sh
63M     .

 

[root@invusomuch-WAS01 ~]# du -a ./apps/jdk1.8.0_275
4       ./apps/jdk1.8.0_275/release
152     ./apps/jdk1.8.0_275/jre/THIRD_PARTY_README
20      ./apps/jdk1.8.0_275/jre/LICENSE
4       ./apps/jdk1.8.0_275/jre/ASSEMBLY_EXCEPTION
4       ./apps/jdk1.8.0_275/jre/lib/meta-index
0       ./apps/jdk1.8.0_275/jre/lib/applet
63888   ./apps/jdk1.8.0_275/jre/lib/rt.jar
12      ./apps/jdk1.8.0_275/jre/lib/psfontj2d.properties
.
....

 

[root@invusomuch-WAS01 ~]# du -d 2 ./apps
108740  ./apps/jdk1.8.0_275/jre
1540    ./apps/jdk1.8.0_275/sample
1940    ./apps/jdk1.8.0_275/man
38284   ./apps/jdk1.8.0_275/lib
696     ./apps/jdk1.8.0_275/bin
216     ./apps/jdk1.8.0_275/include
203100  ./apps/jdk1.8.0_275
76      ./apps/cronolog-1.6.2/sbin
8       ./apps/cronolog-1.6.2/info

 

[root@invusomuch-WAS01 ~]# du -hd 2 ./apps
107M    ./apps/jdk1.8.0_275/jre
1.6M    ./apps/jdk1.8.0_275/sample
1.9M    ./apps/jdk1.8.0_275/man
38M     ./apps/jdk1.8.0_275/lib
696K    ./apps/jdk1.8.0_275/bin
216K    ./apps/jdk1.8.0_275/include
199M    ./apps/jdk1.8.0_275
76K     ./apps/cronolog-1.6.2/sbin
8.0K    ./apps/cronolog-1.6.2/info

 

# GB의 디렉토리를 표시
[root@invusomuch-WAS01 ~]# du -h | grep [0-9]G
7G      ./apps/log-1.6.2/sbin
8.0G    ./apps/log-1.6.2/info

# MB의 디렉토리를 표시
[root@invusomuch-WAS01 ~]# du -h | grep [0-9]G
5.4M    ./apps/test/bin
8.2G    ./apps/test/info

 

# 디렉토리별로 용량을 확인하고, 용량 크기별로 정렬
[root@invusomuch-WAS01 ~]# du -S | sort -n
728x90

댓글