LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-30-2024, 01:26 PM   #1
Stefan69
LQ Newbie
 
Registered: Jan 2024
Posts: 7

Rep: Reputation: 0
Why symlinks do not contain the paths?


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?
 
Old 04-30-2024, 02:01 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
What did you do to “check the file”?
On my system
Code:
 ls  -l
Shows the path to the target file.
 
1 members found this post helpful.
Old 04-30-2024, 02:20 PM   #3
Stefan69
LQ Newbie
 
Registered: Jan 2024
Posts: 7

Original Poster
Rep: Reputation: 0
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?
 
Old 04-30-2024, 03:25 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,705

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by Stefan69 View Post
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.
 
Old 04-30-2024, 03:38 PM   #5
Stefan69
LQ Newbie
 
Registered: Jan 2024
Posts: 7

Original Poster
Rep: Reputation: 0
No offense but I think you should go back to basics before giving advice on forums. I will give you just one good link where you could start:

https://manpages.debian.org/buster/m...link.7.en.html

"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"
 
Old 04-30-2024, 04:14 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
How are you reading the contents of the symlink?

From man symlink:

Code:
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
 
Old 04-30-2024, 04:16 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
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.

https://unix.stackexchange.com/quest...-slow-symlinks
 
5 members found this post helpful.
Old 04-30-2024, 04:24 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,705

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by Stefan69 View Post
No offense but I think you should go back to basics before giving advice on forums. I will give you just one good link where you could start:

https://manpages.debian.org/buster/m...link.7.en.html

"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.
 
2 members found this post helpful.
Old 04-30-2024, 04:25 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,705

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by michaelk View Post
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.

https://unix.stackexchange.com/quest...-slow-symlinks
Good reference, michaelk.
 
Old 04-30-2024, 05:07 PM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,244

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Are you sure that you're not checking a symlink that actually does contain only the name? They exist.

Code:
❯ touch a.txt
❯ ln -s a.txt b.txt
❯ ln -s (pwd)/a.txt c.txt
❯ ls -l
total 8
-rw-r--r--. 1 dugan dugan  0 Apr 30 15:07 a.txt
lrwxrwxrwx. 1 dugan dugan  5 Apr 30 15:07 b.txt -> a.txt
lrwxrwxrwx. 1 dugan dugan 39 Apr 30 15:07 c.txt -> /home/dugan/Documents/symlinktest/a.txt
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?

Post screenshots.

Last edited by dugan; 04-30-2024 at 05:23 PM.
 
Old 04-30-2024, 05:29 PM   #11
rokytnji
LQ Veteran
 
Registered: Mar 2008
Location: Waaaaay out West Texas
Distribution: antiX 23, MX 23
Posts: 7,143
Blog Entries: 21

Rep: Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481Reputation: 3481
Rox file manager tells me

https://pixhost.to/show/433/464991948_screenshot.jpg
 
Old 04-30-2024, 05:34 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,244

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Quote:
Originally Posted by TB0ne View Post
There is no 'path' in a symlink...it's a pointer to the inode of the resource you linked to.
That's wrong. A pointer to an inode is literally a hard link.

Last edited by dugan; 04-30-2024 at 05:50 PM.
 
Old 04-30-2024, 05:57 PM   #13
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,244

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
@Stefan69

The answer to your question is going to be filesystem-specific, but I found you information on how symbolic links are implemented in ext4.

https://ext4.wiki.kernel.org/index.p...Symbolic_Links

Last edited by dugan; 04-30-2024 at 09:10 PM.
 
Old 05-01-2024, 12:07 AM   #14
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,639
Blog Entries: 19

Rep: Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469
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.
 
Old 05-01-2024, 03:22 AM   #15
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,843

Rep: Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507
Quote:
Originally Posted by hazel View Post
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:
Code:
$ ls -ls config vmlinuz
0 lrwxrwxrwx 1 root root 25 2024-04-27 22:37 config -> config-generic-6.6.29.x64
0 lrwxrwxrwx 1 root root 22 2024-04-27 22:37 vmlinuz -> vmlinuz-generic-6.6.29
But:
Code:
$ 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!
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Transfer files whose paths or filenames contain characters prohibited by Microsoft. rcdawson Linux - Software 10 03-10-2022 06:16 PM
absolute paths .Relative paths .I dont know where am i wrong hexle Linux - Newbie 4 08-31-2016 05:34 AM
[SOLVED] Apache 2.x: http for some paths and https for other paths john lee Linux - Newbie 2 07-17-2012 01:33 AM
[SOLVED] How to find files that contain one string, but don't contain another. PatrickDickey Linux - Newbie 2 09-11-2011 06:00 AM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 10:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration