1

I have an example to better illustrate what I'm talking about:

$ touch tas
$ ln -s /etc/leviathan_pass/leviathan3 /tmp/l2/tas
ln: failed to create symbolic link '/tmp/l2/tas': File exists

Basically I can only symlink if the file I want to link doesn't exist. I understand this issue when talking about hard links - there's no way of linking two different files as it would lead to an inode conflict (so the file must be created at the time the command is running, to assure, and I'm presuming, they both "point" to the same inode). Now when talking about soft links it doesn't make sense to me, symlinks have nothing to do with the inodes, so what could be the problem?

Thanks in advance for any help.

ibuprofen
  • 2,890
arpg
  • 13

1 Answers1

1

The command ln won’t clobber existing files by default. You can use ln -sf TARGET LINK_NAME to force overwriting the destination path (LINK_NAME) with a symlink.

You can use ln -f TARGET LINK_NAME to overwrite LINK_NAME with a hard link to, your explanation doesn’t make any sense about inode conflict. It just replaces the file. You are partially right that the target has to exist first for hard links.

jsbillings
  • 24,406
  • @zevzek good point. You want to do this so any process that is trying to open the LINK_NAME path will succeed and have good data (no zero length files, for example) – jsbillings Aug 29 '21 at 00:50
  • Ok, got it. About the hard link explanation I initially gave, well if a file already exists, it has already an inode associated, but when a hard link is done, we're basically pointing the filename of that same file to the inode of the target_file, that was the "conflict" I was talking about, but the command ln could indeed just overwrite it; it doesn't do it just because this formal question then, I see. – arpg Aug 29 '21 at 10:16