Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why symlinks do not contain the paths? Everywhrre you read about symlinks you are told the symlink file data contains the target file path+name but when you check the file it contains only the name. Where is the path stored? I am not interested in the actual command to find the path. Iam interested to know where the path is actially stored and maybe an explanation why is not together with the name?
As I mentioned I am interested to know where the path is actually stored, because it is common belief that the path+name is stored as a text in the file's data/content. If you read the file as a text you do see the name of the target file which corresponds with the file size in bytes of the symlink file and indicate that the path is not stored togetber with the name. The line commands (including the one you used) process the symlink file then show the target path. This doesn't answer my question of where the path is stored?
As I mentioned I am interested to know where the path is actually stored, because it is common belief that the path+name is stored as a text in the file's data/content. If you read the file as a text you do see the name of the target file which corresponds with the file size in bytes of the symlink file and indicate that the path is not stored togetber with the name. The line commands (including the one you used) process the symlink file then show the target path. This doesn't answer my question of where the path is stored?
There is no 'path' in a symlink...it's a pointer to the inode of the resource you linked to. You can DISPLAY it with "ls -l" easily. And I've never heard of the 'common belief' that it's a text file. A bit of basic research will tell you how symlinks are created and what they are.
A symbolic link is a special type of file whose contents
are a string that is the pathname of another file, the file to which
the link refers. (The contents of a symbolic link can be read using
readlink(2).)
Use readlink to read the contents of a symlink and you will see it does indeed contain the path. But note also that there is no requirement that the object referenced by a symlink actually exists.
Last edited by astrogeek; 04-30-2024 at 04:15 PM.
Reason: code formatting
There are fast and slow symbolic links. With modern linux filesystems inodes have the capability of directly storing data of small files so with small path names it would be stored within.
"A symbolic link is a special type of file whose contents are a string that is the pathname of another file, the file to which the link refers"
You claim to be interested in knowing things, yet when you're told you respond like this?? I think you should actually read and understand what you post before making snotty comments. Very first line of that page:
Quote:
Symbolic links are files that act as pointers to other files.
...so a pointer...which is exactly what you were told. Further down that same page:
Quote:
A symbolic link is a special type of file whose contents are a string that is the pathname of another file, the file to which the link refers. (The contents of a symbolic link can be read using readlink(2).)
Did you look at readlink??? See how it uses openat, and what that looks at??? The mere fact that you opened a symbolic link file and did *NOT* find the path would indicate that it doesn't store it, wouldn't it???
The path is still a pointer to the inode of the original file; if you move/delete that file, that invalidates the link, and causes a dangling link. A hardlink is different, allowing you to move the file on the same filesystem without breakage.
There are fast and slow symbolic links. With modern linux filesystems inodes have the capability of directly storing data of small files so with small path names it would be stored within.
The b.txt symlink contains only "a.txt", while the c.txt symlink contains "/home/dugan/Documents/symlinktest/a.txt".
And anyway, you need to answer this question that was asked of you repeatedly:
Quote:
Everywhrre you read about symlinks you are told the symlink file data contains the target file path+name but when you check the file
Quote:
If you read the file as a text you do see the name of the target file which corresponds with the file size in bytes of the symlink file and indicate that the path is not stored togetber with the name.
How are you "checking" this? Are you mounting the filesystem in Windows and opening the symlinks with Notepad or something?
You learn something every day! I had no idea that some symbolic links store the link in the inode. Just out of curiosity, do such links use a data block at all?
I just took a look at the links in my /boot directory. They are of different sizes running from 24 to 38 bytes and the size correlates exactly with the length of the link string.
You learn something every day! I had no idea that some symbolic links store the link in the inode. Just out of curiosity, do such links use a data block at all?
I just took a look at the links in my /boot directory. They are of different sizes running from 24 to 38 bytes and the size correlates exactly with the length of the link string.
The first column tells they don't use data blocks:
$ ln -s 'Short link does not use data blocks' fast
$ ln -s 'This is a slow link that should not fit in the inode any more!' slow
$ ls -ls fast slow
0 lrwxrwxrwx 1 kaukasoi users 35 2024-05-01 11:20 fast -> Short\ link\ does\ not\ use\ data\ blocks
4 lrwxrwxrwx 1 kaukasoi users 62 2024-05-01 11:20 slow -> This\ is\ a\ slow\ link\ that\ should\ not\ fit\ in\ the\ inode\ any\ more!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.