1

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?

  • You might find this useful. – terdon Sep 3 '13 at 3:41
4

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.

  • 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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