2008年11月1日土曜日

hard linkとdu

hard linkしたときduで正確な値がでるのかどうかを確認.結論はでる.
mkdir /tmp/test1
mkdir /tmp/test2
dd if=/dev/null of=/tmp/test1/test0 count=10000
/tmp/test1/test0 にテスト用のファイルを作った.これをtest2からハードリンクする.
> cd /tmp/test2
> ln ../test1/test0
確認.確かに同じinodeになっている.
> ls -ial /tmp/test1
total 5024
1015814 drwxr-xr-x 2 root root    4096 Oct 24 13:35 .
1015809 drwxrwxrwt 9 root root    4096 Oct 24 13:35 ..
1015815 -rw-r--r-- 2 root root 5120000 Oct 24 13:35 test0
> ls -ial /tmp/test2
total 5024
1015817 drwxr-xr-x 2 root root    4096 Oct 24 13:35 .
1015809 drwxrwxrwt 9 root root    4096 Oct 24 13:35 ..
1015815 -rw-r--r-- 2 root root 5120000 Oct 24 13:35 test0
> cd /tmp
> du -s .
...
5016 test1
4 test2
たしかに,最初に作った test1のほうの容量だけが計上される.ちなみにtest1からの参照を削除するとちゃんとtest2のほうに計上される.
> rm test1/test0
> du -s .
...
4 test1
5016 test2

0 件のコメント: