
これは主に理論的な問題であり、実際には実際には使用されません。
ご存知のように、ファイル名はディレクトリ inode に保存されます。つまり、ファイルが多いほど、ファイル名が長いほど、ディレクトリが使用するスペースも多くなります。
残念ながら、ディレクトリからファイルを削除すると、ディレクトリで使用されているスペースは解放されず、引き続き使用されます。
$ mkdir test ; cd test
# next command will take a while ; for me it was about 6 minutes
$ for ((i=1;i<103045;i++)); do touch very_long_name_to_use_more_space_$i ; done
$ ls -lhd .
drwxr-xr-x 2 user user 8.6M Nov 9 22:36 .
$ find . -type f -delete
$ ls -l
total 0
$ ls -lhd .
drwxr-xr-x 2 user user 8.6M Nov 9 22:39 .
ファイルが削除された後にディレクトリが使用するスペースが更新されないのはなぜですか?ディレクトリを再作成せずにスペースを解放する方法はありますか?
答え1
fsck.ext4 -D
アンマウントされたファイルシステムで最適化されたディレクトリを使用できます。
-D Optimize directories in filesystem. This option causes e2fsck to try to optimize all directories, either by reindexing them if the filesystem supports directory indexing, or by sorting and compressing directories for smaller directories, or for filesys‐ tems using traditional linear directories.
ext3
このオプションはおよびでも有効ですext2
。
なぜインスタントで行われなかったのかは言えません。おそらくパフォーマンスの問題のためですか?