0
0

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 1 year has passed since last update.

ディスク容量に関するコマンド

Last updated at Posted at 2023-12-18

問題:/varの空きディスク容量を調べよ。

$ df -h /var
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/xvda4       9.4G  1.7G  7.7G   19% /

ポイント:
-hオプションで単位を分かりやすくしている。
dfはディレクトリを指定しても、マウントされているファイルシステム(パーティション)ごとにしか表示されない。

問題:/varの使用ディスク容量を調べよ。

$ sudo du -sh /var
242M    /var

ポイント:
sudoで実行して、アクセス権がないフォルダがないようにしている。
-hオプションで単位を分かりやすくしている
-sオプションで合計のみを表示している。

問題:/var直下のディレクトリの使用ディスク容量を多い順に並べよ。

$ sudo du -d1 /var | sort -n -r
247244  /var
140660  /var/lib
90224   /var/cache
16336   /var/log
12      /var/spool
4       /var/tmp
0       /var/yp
0       /var/preserve
0       /var/opt
0       /var/nis
0       /var/local
0       /var/kerberos
0       /var/games
0       /var/ftp
0       /var/empty
0       /var/db
0       /var/crash
0       /var/adm

ポイント:
-d1オプションはディレクトリの一つ目の階層まで集計するという意味。
-hオプションは並べ替えがうまく行かなくなるので使用しない。
sortの-nオプションは数値順、-rは降順(大きい順)に並べ替えるという意味。

問題:/var配下の使用ディスク容量の多いファイル上位10個を表示せよ。

$ sudo du -b /var/* | sort -n | tac | head
140038755       /var/lib
118812763       /var/lib/rpm
92210525        /var/cache
90759519        /var/cache/dnf
29330297        /var/cache/dnf/rhel-9-appstream-rhui-rpms-8f1a568bacbcbf4a
29330130        /var/cache/dnf/rhel-9-appstream-rhui-rpms-8f1a568bacbcbf4a/repodata
17047884        /var/cache/dnf/rhel-9-baseos-rhui-rpms-0ae242d3c2853ed8
17047720        /var/cache/dnf/rhel-9-baseos-rhui-rpms-0ae242d3c2853ed8/repodata
16055985        /var/log
14085685        /var/lib/selinux
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?