useful difference between hardlink and copy

You can make multiple hard links to the same file without worrying about disk space. This is very useful (depending on how you use or implement it) in taking snapshots of directories, yum repositories, etc.

[Linux: marc@localhost tmp]$ dd if=/dev/zero of=bigfile bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.0149572 s, 1.4 GB/s
 
[Linux: marc@localhost tmp]$ ln bigfile bigfile-ln
 
[Linux: marc@localhost tmp]$ cp bigfile bigfile-cp
 
[Linux: marc@localhost tmp]$ ls -lh bigfile*
-rw-r--r-- 2 marc marc 20M Feb 26 00:32 bigfile
-rw-r--r-- 1 marc marc 20M Feb 26 00:33 bigfile-cp
-rw-r--r-- 2 marc marc 20M Feb 26 00:32 bigfile-ln
 
[Linux: marc@localhost tmp]$ du -sh bigfile*
20M     bigfile
20M     bigfile-cp
 
[Linux: marc@localhost tmp]$ rm bigfile
 
[Linux: marc@localhost tmp]$ du -sh bigfile*
20M     bigfile-cp
20M     bigfile-ln

No comments:

Post a Comment