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?

1
  • You might find this useful.
    – terdon
    Sep 3, 2013 at 3:41

1 Answer 1

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.

2
  • 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? Sep 3, 2013 at 2:25
  • This turned out to be much more involved than I realized - I've edited my answer. Sep 3, 2013 at 2:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .