A
A
Asker18882020-12-11 22:06:05
*nix-like systems
Asker1888, 2020-12-11 22:06:05

Why does creating a hard link (ln) increase memory usage?

Hello! Question about the ln command to create a hard link to a file.
After reading the information about files, inodes, hard and symbolic links to files, I concluded that:
1. The file takes up a certain amount of memory on the disk;
2. Each file has a unique inode for the system, which points to the memory area where the file data is located;
3. When `ln file1 file2` is executed, the second file is essentially a pointer to the same memory area. same as file1. Those. work in them goes under different names, but the same memory area is rewritten.
At the same time, if you look at the weight of the directory in which a hard link to a file in the same directory was created, you can see that the weight has increased exactly by the weight of the linked file.
If the memory area is the same, and the work is done with the same bits, then why is the additional memory occupied?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
ComodoHacker, 2020-12-11
@Asker1888

And how do you look at the "weight of the directory"?
If the command is ls , then its task is to display the names, sizes and other attributes of files, without understanding how the files are physically stored. And ls does its job well.
If you want to take into account all the nuances with links, use the du command . She has keys that determine how to count the occupied space.

R
Rozello, 2021-02-13
@Rozello

Most likely there is no magic.
It's just that the file manager iterates the files in the directory, extracts the file size for each and then adds the resulting values.
If the file manager does not have a separate logic processing links, then it will consider each link as a separate file and, accordingly, exaggerate the total size of the files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question