2013. 12. 18. 11:01

[Linux/Ubuntu 파일 시스템 관리] file system 사용량 측정하기 (df, du)

개별 file system에 대해 현재 사용중인 용량과 남은 용량을 체크하기 위해서는 df 명령을 사용한다. file 이나 directory에 대해 체크하려면 du 명령을 사용한다.


df 명령은 mount된 file system의 요약을 보여준다. -h 를 사용하면 단위가 M(ega) 혹은 G(iga)로 변환되어 읽기가 쉽다.

~$ df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sdb5              35G  2.7G   30G   9% /

none                  242M  660K  241M   1% /dev

none                  249M  168K  248M   1% /dev/shm

none                  249M  104K  248M   1% /var/run

none                  249M     0  249M   0% /var/lock

/dev/sda1              40G  2.3G   38G   6% /mnt/windows

//xx.xxx.xxx.xxx/XXX  3.2T  2.6T  619G  81% /mnt/windows_share

~$


ext file system인 경우 mkfs로 생성될 때 많은 inode들로 시작하는데, 만약 이후에 수많은 file이 관리되는 시스템으로 된 경우 inode의 부족이 발생할 수 있다.  이를 체크하려면 -i를 사용한다.

~$ df -hi

Filesystem            Inodes   IUsed   IFree IUse% Mounted on

/dev/sdb5               2.2M    148K    2.1M    7% /

none                     61K     837     60K    2% /dev

none                     63K       5     63K    1% /dev/shm

none                     63K      53     62K    1% /var/run

none                     63K       3     63K    1% /var/lock

/dev/sda1                38M     12K     38M    1% /mnt/windows

//xx.xxx.xxx.xxx/XXX       0       0       0    -  /mnt/windows_share

~$


local file system만 확인하려면, -l을 추가한다.

~$ df -hl

Filesystem            Size  Used Avail Use% Mounted on

/dev/sdb5              35G  2.7G   30G   9% /

none                  242M  660K  241M   1% /dev

none                  249M  168K  248M   1% /dev/shm

none                  249M  104K  248M   1% /var/run

none                  249M     0  249M   0% /var/lock

/dev/sda1              40G  2.3G   38G   6% /mnt/windows

~$


file system의 종류를 확인하려면 -T를 추가한다.

~$ df -hT

Filesystem    Type    Size  Used Avail Use% Mounted on

/dev/sdb5     ext4     35G  2.7G   30G   9% /

none      devtmpfs    242M  660K  241M   1% /dev

none         tmpfs    249M  168K  248M   1% /dev/shm

none         tmpfs    249M  104K  248M   1% /var/run

none         tmpfs    249M     0  249M   0% /var/lock

/dev/sda1  fuseblk     40G  2.3G   38G   6% /mnt/windows

//xx.xxx.xxx.xxx/XXX

              cifs    3.2T  2.6T  619G  81% /mnt/windows_share

~$


특정 파일이나 directory 별 사용량을 체크하려면 du 명령을 사용한다.

~$ du -h /var/run

4.0K /var/run/console

0 /var/run/vmblock-fuse/blockdir

0 /var/run/vmblock-fuse

du: cannot read directory `/var/run/gdm': Permission denied

0 /var/run/gdm

4.0K /var/run/ConsoleKit

du: cannot read directory `/var/run/cups/certs': Permission denied

0 /var/run/cups/certs

8.0K /var/run/cups

0 /var/run/pm-utils/pm-powersave/storage

0 /var/run/pm-utils/pm-powersave

0 /var/run/pm-utils/locks

0 /var/run/pm-utils

0 /var/run/pppconfig

8.0K /var/run/avahi-daemon

4.0K /var/run/dbus

0 /var/run/udev-configure-printer

4.0K /var/run/network

0 /var/run/sendsigs.omit.d

92K /var/run

~$

개별 파일의 요량을 합산하여 directory 별로 종합하여 표시하려면 -s를 사용한다. 접근 오류인 경우 root 권한으로 시도해 본다.

~$ du -sh /var/run

du: cannot read directory `/var/run/gdm': Permission denied

du: cannot read directory `/var/run/cups/certs': Permission denied

92K /var/run

~$ sudo du -sh /var/run

104K /var/run

~$


여러개의 directory를 확인하려면 -c를 사용한다.

~$ sudo du -sch /home /var

271M /home

248M /var

518M total

~$


특정한 pattern을 제외시키려 한다면, 다음과 같다.

~$ sudo du -sh --exclude='*.gz' /home/

213M /home/

~$


--max-depth를 이용하여 directory 탐색시 depth를 조절할 수 있다.

~$ sudo du -h --max-depth=1 /var/run

4.0K /var/run/console

0 /var/run/vmblock-fuse

8.0K /var/run/gdm

4.0K /var/run/ConsoleKit

12K /var/run/cups

0 /var/run/pm-utils

0 /var/run/pppconfig

8.0K /var/run/avahi-daemon

4.0K /var/run/dbus

0 /var/run/udev-configure-printer

4.0K /var/run/network

0 /var/run/sendsigs.omit.d

104K /var/run

~$ sudo du -h --max-depth=2 /var/run

4.0K /var/run/console

0 /var/run/vmblock-fuse/blockdir

0 /var/run/vmblock-fuse

4.0K /var/run/gdm/auth-for-greenfish-JMMGQ1

4.0K /var/run/gdm/auth-for-gdm-3fwXIA

8.0K /var/run/gdm

4.0K /var/run/ConsoleKit

4.0K /var/run/cups/certs

12K /var/run/cups

0 /var/run/pm-utils/pm-powersave

0 /var/run/pm-utils/locks

0 /var/run/pm-utils

0 /var/run/pppconfig

8.0K /var/run/avahi-daemon

4.0K /var/run/dbus

0 /var/run/udev-configure-printer

4.0K /var/run/network

0 /var/run/sendsigs.omit.d

104K /var/run

~$