"ls"コマンドがどのように機能するのかわかりません。

フォルダのサイズを確認したいので、pg_backup次のコマンドを使用しました。

[postgres@server02 ~]$ pwd
/var/lib/pgsql

[postgres@server02 ~]$ ls -lh
total 4.0K
drwxr-x---. 7 postgres postgres   86 Oct  6 22:00 pg_backup

上記の出力に示すように、サイズは86バイトです。

ただし、pg_backupディレクトリ自体には複数の異なるディレクトリが含まれています。

[postgres@server02 ~]$ ls -lh pg_backup
total 0
drwxr-xr-x. 3 postgres postgres 121 Oct  2 23:00 20211002
drwxr-xr-x. 2 postgres postgres 109 Oct  3 22:00 20211003
drwxr-xr-x. 2 postgres postgres 109 Oct  4 22:00 20211004
drwxr-xr-x. 2 postgres postgres 109 Oct  5 22:00 20211005
drwxr-xr-x. 2 postgres postgres 109 Oct  6 22:00 20211006
[postgres@server02 ~]$

その後、これらのサブディレクトリの1つにいくつかの大容量ファイルが含まれています。

[postgres@server02 ~]$ ls -lh pg_backup/20211006
total 23G
-rw-r--r--. 1 postgres postgres  23G Oct  6 23:21 file.dump
-rw-r--r--. 1 postgres postgres 418K Oct  6 22:00 backup_dba.dump
-rw-r--r--. 1 postgres postgres 1.4K Oct  6 22:00 backup_postgres.dump
-rw-r--r--. 1 postgres postgres  830 Oct  6 22:00 backup_dwh.dump

実際、ディレクトリには最大23 GBのファイルを含むより大きなサブディレクトリがたくさん含まれていますが、なぜls -lhコマンドに86バイトのサイズしか表示されないのか混乱しています。すべてのサブディレクトリのファイルの総数が初期コマンドに反映されないpg_backupのはなぜですか?pg_backupls -lh

ベストアンサー1

lsファイルが消費するサイズを表示します。仕事の多くを簡素化すると、Unixシリーズシステムの多くはファイルのように見えます。一部はファイルファイル、一部はソケットファイル、一部はシンボリックリンクファイル、一部はディレクトリファイルなどです。出力に表示されるサイズlsは、オブジェクトが使用するサイズです。ただし、ターゲットオブジェクトのサイズは考慮されません。

あなたが探している

du -h -d 0 <directory>

注文する。寸法はlsあなたに示されています - まあ、そうではありません。はい、ディレクトリにはより多くのサブディレクトリが含まれているため、サイズが大きくなります。しかし、2つのサイズは異なることを測定します。

おすすめ記事