Results 1 to 4 of 4
So if there are several links in the system pointing to a particular file and the file is then moved what happens?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-22-2011 #1
- Join Date
- Oct 2011
- STL, USA
Hard and Soft Links?
- 10-22-2011 #2
- Join Date
- Oct 2007
- Tucson AZ
Nothing, I expect. You will probably get an error message like file not found or couldn't open file.
Never actually tried this myself.
- 10-22-2011 #3
It depends on what you move. If foo1 foo2 foo3 and foo4 are links to the same data,
if you move foo1, the data has not moved, only the link has moved. You assume that
when you move a file to another place you are moving the data, but that is not necessarily
- 10-23-2011 #4
So, it depends on what sort of link you have.
The way that UNIX filesystems work is that the filesystem contains a link to an inode. The inode contains information like the permissions of the file, where it is actually stored on disk, etc. When I say link here, I refer to what is sometimes called a "hard link". So there can be multiple "hard links" to a single inode.
The "mv" command is basically a wrapper around "create a new link, remove the old link". So when you say "mv foo bar", it actually runs:
ln foo bar # Create a new link "bar" that points to the inode pointed at by "foo" rm foo # Remove the link "foo"
link1 link2 | | | | |--> inode <------
So if we have this situation:
link1 link3 | | | | |--> inode <------
A symbolic link (aka soft link) is a totally different story. A symbolic link points to a specific filepath. So, we might have a situation like this:
symlink ---> /home/user/file /home/user/file ---> inode
symlink ---> /home/user/file /home/user/different_file ---> inode