6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

du, df コマンド

Posted at

この記事は Linux コマンド 全部オレ Advent Calendar 2017 の10日目の記事です。

du

NAME
       du - estimate file space usage

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

DESCRIPTION
       Summarize disk usage of each FILE, recursively for directories.

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

ディレクトリやファイル容量を確認するコマンド。
ファイルサイズではなく、専有しているブロックサイズを表示するので、ファイルサイズより大きくなる。

よく使いそうな使い方

## ルートディレクトリの名ディレクトリの容量を確認する
[sinsengumi ~]# du -shc /*
0	/bin
110M	/boot
0	/dev
30M	/etc
0	/home
0	/lib
0	/lib64
0	/media
0	/mnt
0	/opt
0	/proc
20M	/root
8.4M	/run
0	/sbin
0	/srv
0	/sys
0	/tmp
778M	/usr
109M	/var
1.1G	合計


## 今いるディレクトリ内にある各ディレクトリの容量をディレクトリ毎に表示する(カレントディレクトリのファイルは含まない)
[sinsengumi ~]# tree -a
.
├── .bash_history
├── .bash_logout
├── .bash_profile
├── .bashrc
├── .cshrc
├── .tcshrc
├── anaconda-ks.cfg
├── dir1
│   ├── .dir
│   │   └── 5000k
│   ├── 1000k
│   └── dir1_1
│       └── 4000k
└── dir2
    └── 10000k

4 directories, 11 files
[sinsengumi~]# du -s ./*/
10000	./dir1/
10000	./dir2/

df

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_COR‐
       RECT 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.

ディスク容量を確認するコマンド。

よく使いそうな使い方

[sinsengumi ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G  981M   17G   6% /
devtmpfs                 910M     0  910M   0% /dev
tmpfs                    920M     0  920M   0% /dev/shm
tmpfs                    920M  8.4M  912M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    184M     0  184M   0% /run/user/0


## ディレクトリをしているすると、そのディレクトリが含まれる(マウントされてる)ファイルシステムのみを表示する
[sinsengumi ~]# df -h /home/
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G  981M   17G   6% /

[sinsengumi ~]# df -h /boot/grub
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1      1014M  142M  873M  14% /boot
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?