Solved Does symbolic link consume an additional inode?

Solved issue

CaffeineAddict

Well-Known Member
Joined
Jan 21, 2024
Messages
488
Reaction score
311
Credits
4,048
I understand that when a hard link is created to another file this means that both the original file and hard link itself will consume same inode (pointing to same data on disk) thus 1 inode is consumed in total, is that correct?

But when we create a symbolic link how many inodes are consumed?
I understnand that original file will consume an inode (so that's 1), but does the symbolic link itself consume a new separate inode as well (independed of the inode of the original file)? so that 2 independent (but not same) inodes are in use.

In addition to this question, how exactly are symbolic links vs hard links stored on file system?
 


Existing file is file1:
Code:
[tom@min ~]$ ls
file1

Create a symbolic link to file1 named flink
Code:
[tom@min ~]$ ln -s file1 flink

List files:
Code:
[tom@min ~]$ ls -al
-rw-r--r-- 1 ben ben    0 Feb  6 07:23 file1
lrwxrwxrwx 1 ben ben    5 Feb  6 07:25 flink -> file1

Determine inode number of file1
Code:
[tom@min ~]$ stat file1
  File: file1
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 259,3   Inode: 19433505    Links: 1
<snip>

Determine inode number of flink
Code:
[tom@min ~]$ stat flink
  File: flink -> file1
  Size: 5               Blocks: 0          IO Block: 4096   symbolic link
Device: 259,3   Inode: 19433506    Links: 1
<snip>

Inode numbers differ, so each file, that is, the original file and the link file, each have their own inode.
 
Last edited:
Awesome thanks, in addition I learned about new command stat :)

Therefore symbolic link itself is treated as regular file in terms of disk space usage? for instance it consumes a sector on disk?
Except that it's not a regular file but symbolic link.
 
The link won't consume a sector on a disk because it's not using space, rather it'll be an entry in the directory's "journal", the directory being a file of entries about the files within its "domain".
 
If I understand this means if a symbolic link is within some folder named "foo" then the foo maintains a list of symbolic links that which it contains?
So the only space used is that by the foo itself?
 
In this long listing of directories, it's clear that each directory has a space allocation.
Code:
drwxr-xr-x  2 tom tom 4.0K Nov 17 21:07 Desktop
drwxr-xr-x  3 tom tom 4.0K Dec  2 07:06 docs
drwxr-xr-x  6 tom tom 4.0K Feb  3 17:28 Downloads
-rw-r--r--  1 tom tom    3 Feb  1 15:07 file
drwxr-xr-x  3 tom tom 4.0K Jan 24 18:10 friends
drwxr-xr-x 12 tom tom 4.0K Jan 19 13:20 graphics
drwxr-xr-x  2 tom tom  20K May 15  2009 howtos

The space allocation is for a "directory file" that holds data about the files within that directory.
The single ordinary file is 3 bytes.
Most directories are showing a size of 4 kilobytes, so the directory files are mostly 4 k in size.
One directory file is 20 kilobytes.

The "howtos" directory file is much larger because over time, it's contents was increased by the addition of files by the user so the size of the directory file needed to enlarge to keep it's data in order and show all the files within the directory accurately. It originally was a directory file of 4 k which is the default on a lot of linux systems.

The directory file, though a file, is not ordinarily readable since the operating system makes all the changes according the instructions received. The directory contents are the ordinarily readable items.

The directory file contains file metadata, some of which consists of the list of the inode numbers of each file, including link files of course, and then lists the pointers associated with each inode that point to the blocks that contain the file data. The metadata with the pointers enable the accurate output of the commands used to list files. Does that make sense?
 
Last edited:

Members online


Latest posts

Top