Symbolic link to an empty file shows size 2

Hi,

I have created an empty file and a symbolic link to a file. But when I issue the following commands, I am getting the output 2.

stat -c "%s"  linkfile
du -hb linkfile

Why this is happening?

Because the symbolic link is a file that contains the name of the file it points to. Is the name of the empty file by any chance 2 bytes long?

Regards,
Alister

The size of the empty (original) file shows 0 always. But do you mean, since the symbolic link holds the name of the target empty file, it has the size 2?? If so, then the minimum size of any symbolic link file is always 2 not 0, even though it points to an empty file, right? Note, I am using Ubuntu 8.04 (32 bit machine)

No, not always 2 bytes, but always the length of the path it's pointing to. If you create a (symbolic) link to a file in the current directory called 'a', the "size" of the (symbolic) link will be 1. If the name is 'abcde', the size will be 5. And the link to the file /usr/share/doc/installation-report/install-report.template will have a size of 58.

Yea, correct. Thanks a ton for clarification !! :slight_smile: