PR

【簡単】Linuxでファイルサイズを一括で確認するコマンド

CentOS

Linuxでフォルダ内のファイルサイズを一括で確認したいとき、便利なコマンドを紹介します。

1. ls コマンドを使う

ls -lh を使うと、ファイルサイズが人間が読みやすい形式で表示されます。

ls -lh

実行例

# ls -lh
total 103M
-rw-r--r-- 1 root root 789K Feb  5 03:26 AmazonSSMAgent-update.txt
-rw-r--r-- 1 root root  15M Feb  7 16:08 amazon-ssm-agent.log
-rw-r--r-- 1 root root 244K Sep  5 08:43 amazon-ssm-agent.log.16
-rw-r--r-- 1 root root  29M Oct 16 02:46 amazon-ssm-agent.log.17
-rw-r--r-- 1 root root  29M Nov 13 23:30 amazon-ssm-agent.log.18
-rw-r--r-- 1 root root  29M Jan 16 16:49 amazon-ssm-agent.log.19
-rw-r--r-- 1 root root  56K Jan 16 16:49 amazon-ssm-agent.log.20
drwx------ 2 root root 4.0K Feb  7 07:05 audits
-rw-r--r-- 1 root root 514K Feb  7 11:14 errors.log
-rw-r--r-- 1 root root  756 Mar 12  2023 hibernate.log
drwxr-xr-x 2 root root 4.0K Mar 12  2023 patch-configuration
drwxr-xr-x 3 root root 4.0K Feb  7 10:45 pb-hashes

2. du コマンドを使う

du コマンドを使うと、ディレクトリごとの合計サイズを確認できます。

du -sh *

実行例

# du -sh *
796K    AmazonSSMAgent-update.txt
15M     amazon-ssm-agent.log
248K    amazon-ssm-agent.log.16
29M     amazon-ssm-agent.log.17
29M     amazon-ssm-agent.log.18
29M     amazon-ssm-agent.log.19
56K     amazon-ssm-agent.log.20
32K     audits
520K    errors.log
4.0K    hibernate.log
72K     patch-configuration
8.0K    pb-hashes

このコマンドは各ファイルとフォルダのサイズをMBやGB単位で表示します。

3. find コマンドで特定のファイルサイズを検索

特定のサイズ以上のファイルを探したい場合は、find コマンドが便利です。

find . -type f -size +10M

実行例

# find . -type f -size +10M
./amazon-ssm-agent.log.18
./amazon-ssm-agent.log
./amazon-ssm-agent.log.19
./amazon-ssm-agent.log.17

この例では、100MB以上のファイルを検索します。

4. stat コマンドで詳細情報を取得

stat コマンドを使うと、特定のファイルの詳細情報を確認できます。

stat filename

実行例

# stat errors.log
  File: errors.log
  Size: 525861          Blocks: 1040       IO Block: 4096   regular file
Device: 10302h/66306d   Inode: 258230      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-03-12 17:36:22.554054903 +0000
Modify: 2025-02-07 11:14:22.528499182 +0000
Change: 2025-02-07 11:14:22.528499182 +0000
 Birth: -

これらのコマンドを活用して、Linux上でファイルサイズを素早く確認しましょう!

タイトルとURLをコピーしました