I'll start by example:

$ ls -l dir1
total 4
-rw-r--r-- 4 maythux maythux 1650 2008-01-10 16:33 file
lrwxrwxrwx 1 maythux maythux  7 2008-01-15 15:17 symfile -> file

symfile is a symlink of the file file

Also as i know 1650 would be the size of the file file, but what is the number 7 that is laid under the size column?

EDIT: Running du:

$ du -sh symfile
0   symfile

So how could you prove that 7 is the symlink size?!


try this

$ touch file
$ du -sh file
0 file
$ ls -l file
-rw-rw-r-- 1 maythux maythux 0 Jun  1 19:42 file

note that size is also here 0.


$ ln -s file sym
$ du -sh sym
0 sym
$ ls -l sym
lrwxrwxrwx 1 maythux maythux 4 Jun  1 19:44 sym -> file

So, I suppose it's not only a size

  • 2
    The 7 depends on the filesystem (and possibly other parameters). It's 7 on ext4, but could be 13 on btrfs and 3 on tmpfs.
    – muru
    Jun 1 '15 at 16:30
  • 1
    It is a size, but the size depends on the filesystem (btrfs presumably stores more metadata than ext4, and ext4 more than tmpfs). You can fill your disk with links. I'm just saying, don't be surprised if you see a different number on a different filesystem.
    – muru
    Jun 1 '15 at 16:38
  • 1
  • 1
    Your directory entry has a minimum size to it, larger than it needs. Make enough entries and the size of the directory will increase. Check with: mkdir foo; ls -ld foo; for i in {1..1000}; do ln -s foo/bar foo/$i; done; ls -ld foo.
    – muru
    Jun 1 '15 at 16:42
  • 1

Symbolic links take the room it takes to store the name and target plus a few bytes for other metadata.

So it is the size of the symlink.

Regarding the size from du -sh: du only looks at how many blocks are allocated, and so may show 0.stat and ls -l are better in showing the size in that regard.

  • then why du -sh symfile gives 0? –
    – Maythux
    Jun 1 '15 at 16:35
  • du only looks at how many blocks are allocated, and so may show 0. stat and ls -l are smarter.
    – Rinzwind
    Jun 1 '15 at 16:45
  • Please read the update
    – Maythux
    Jun 1 '15 at 16:46
  • See my answer: it is the name, target and some metadata. In total it makes up for 7 bytes. Other OS store other metadata and so will have a different size.
    – Rinzwind
    Jun 1 '15 at 16:49
  • The question was "How can you PROVE IT?"
    – Pilot6
    Jun 1 '15 at 16:50

It is the size of the symlink in bytes.

Some file systems have a small area inside the directory entry that is used for the beginning of the file, which significantly speeds up processing of symlinks and small reads (think file) at the expense of larger directory entries.

If the entire symlink contents fit into the directory entry, then no data blocks are allocated, and the du size shows as zero. If the symlink doesn't fit, space is allocated normally (so you end up with a single block allocation), which may be optimized by the filesystem using tail merging (but there is no API for du to know about this).

The ext4 filesystem performs this optimization for symlinks only, the criteria are found in the function ext4_inode_is_fast_symlink.

  • "Some file systems ..." - your answer would be improved if you listed the common file systems with this feature (and any common ones without).
    – R.M.
    Jun 1 '15 at 20:34

This is size of the symlink file in bytes.

Symlink file is a normal file that stores data regarding where is the file it is pointing to. In ext 4 it is 7 bytes.

  • size in what? is it Bytes or bits or What?
    – Maythux
    Jun 1 '15 at 16:30
  • Size in bytes..
    – Pilot6
    Jun 1 '15 at 16:32
  • 1
    then why du -sh symfile gives 0?
    – Maythux
    Jun 1 '15 at 16:33
  • du is not presize with very small files. Try to use du at some 99 bytes file. It will show 4.0K.
    – Pilot6
    Jun 1 '15 at 16:39
  • that's my pioint also then it should at least show 4k for the symlink since in OS concept it's registring a cluster for this file
    – Maythux
    Jun 1 '15 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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