Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I check the file size of a symbolic link by stat(), then it reports a nonzero file size equal to the link path string. But when I use du on the link, it reports a size of zero blocks.

Is there a simple explanation for this? Is it correct to interpret symbolic links as requiring no disk space? Where is the symbolic link information being stored?

share|improve this question
    
You might find this useful. –  terdon Sep 3 '13 at 3:41
add comment

1 Answer

up vote 4 down vote accepted

See https://en.wikipedia.org/wiki/Symlink#Storage_of_symbolic_links. Modern systems use what are called "fast symlinks". No blocks are allocated for the symlink. Instead, the symlink reference is stored in the inode itself, where a regular file stores the locations of the blocks that make it up. du only looks at how many blocks are allocated, and so may show 0. stat and ls -l are smart enough to report the length of the symlink based on the data stored in the inode.

share|improve this answer
    
But if I do du -B1 my_file, it still turns up as zero. Doesn't -b enable the apparent-size flag? Maybe I should be asking where the data is saved? –  marshall.ward Sep 3 '13 at 2:25
    
This turned out to be much more involved than I realized - I've edited my answer. –  wingedsubmariner Sep 3 '13 at 2:44
    
Thank you for the update, this explains it nicely. –  marshall.ward Sep 3 '13 at 2:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.