LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-01-2024, 05:00 AM   #16
Petri Kaukasoina
Senior Member
 
Registered: Mar 2007
Posts: 1,837

Rep: Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507Reputation: 1507

Quote:
Originally Posted by Stefan69 View Post
Why symlinks do not contain the paths?
Quote:
Originally Posted by Stefan69 View Post
"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"
I guess the problem is what the word pathname means in this context. See, for example, https://pubs.opengroup.org/onlinepub...tml#tag_03_271:
Quote:
3.271 Pathname
A string that is used to identify a file. In the context of POSIX.1-2017, a pathname may be limited to {PATH_MAX} bytes, including the terminating null byte. It has optional beginning <slash> characters, followed by zero or more filenames separated by <slash> characters. A pathname can optionally contain one or more trailing <slash> characters. Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters.
What does filename mean above? https://pubs.opengroup.org/onlinepub...tml#tag_03_170:
Quote:
3.170 Filename
A sequence of bytes consisting of 1 to {NAME_MAX} bytes used to name a file. The bytes composing the name shall not contain the <NUL> or <slash> characters. In the context of a pathname, each filename shall be followed by a <slash> or a <NUL> character; elsewhere, a filename followed by a <NUL> character forms a string (but not necessarily a character string). The filenames dot and dot-dot have special meaning. A filename is sometimes referred to as a "pathname component". See also Pathname.
So, these are pathnames, even the first one:
Code:
bash
/bin/bash
/usr/lib/../bin/bash
bin/bash
../../bin/./bash
They may resolve to the same canonicalized absolute pathname, depending on $PWD. Or, in case of symlinks, depending on where the symlink is.
Code:
$ realpath /usr/lib/../bin/bash
/bin/bash
It's often a good idea to not use absolute pathnames in symlinks. For example, if you create a tar archive and extract it to somewhere else, absolute links will stop working correctly. Or, if you mount a file system to a different place in the tree, like mount a linux os root under /mnt of another linux os.

Last edited by Petri Kaukasoina; 05-01-2024 at 05:36 AM.
 
Old 05-01-2024, 07:16 AM   #17
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,678
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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.
I believe that you are referring to a "hard link," TB0ne, not a "symbolic one.

A hard-link is a second directory-entry which refers to the same internal file ("inode"). Whereas a symbolic-link is, indeed, a tiny file containing a filename reference, which Linux resolves by trying to find and open the target file. (You don't know if it will [still ...] work until and unless you try it.)
 
1 members found this post helpful.
Old 05-01-2024, 07:24 AM   #18
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by sundialsvcs View Post
I believe that you are referring to a "hard link," TB0ne, not a "symbolic one.

A hard-link is a second directory-entry which refers to the same internal file ("inode"). Whereas a symbolic-link is, indeed, a tiny file containing a filename reference, which Linux resolves by trying to find and open the target file. (You don't know if it will [still ...] work until and unless you try it.)
Indeed so, and michaelk's link provided a much better explanation. It referenced inodes in the context I was thinking of, but you are correct.
 
Old 05-01-2024, 07:25 AM   #19
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,633
Blog Entries: 19

Rep: Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469Reputation: 4469
Quote:
Originally Posted by sundialsvcs View Post
I believe that you are referring to a "hard link," TB0ne, not a "symbolic one.
That's why, if you delete the actual file, the symlink file will be left dangling and invalid. This is usually signaled in displays with a different colour or a highlight. Whereas if you delete a file with a hard link to it, the linked name still works and nothing has really changed.
 
Old 05-01-2024, 08:12 AM   #20
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,243

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
It’s also why symbolic links work across filesystems, and hard links don’t.
 
  


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 01:57 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