r/linuxmint • • 49m ago

SOLVED XFCE and Symlinks confusing me

I have a file that I open in my text editor (xed) almost daily. For convenience, I wanted to create a symlink on my desktop that would point to the actual file. Coming from windows, I understand this to be the closing thing to a "shortcut". After looking in Thunar for a UI way to create a symlink, I ended up using the ln command, specifically: ln Notes\ Scratchpad.txt ~/Desktop

Sure enough, a new... file? Object? Well, something that -looks- like a text file appeared on my desktop. I checked the properties and nothing I saw indicated it was a symlink, instead it looked just like a copy of the file. To test this, I opened the symlink on the Desktop, made an edit saved and closed. Then opened the file from the actual storage location and it had the same edit - OK, I guess it's a symlink!

Well, I wanted more evidence because it bothers me that it looks JUST LIKE A FILE, both in the UI and when I run ls -l

-rw-rw-r-- 2 steve steve 45942 Dec  3 09:33 'Notes Scratchpad.txt'

I searched on the web and found examples of using the test command, but those results are indicating both objects/files/whatever or regular files (i.e., not symlinks). Note: I ran this command on each of the files

test -h Notes\ Scratchpad.txt && echo "symlink" || echo "reg file"

I'm confused - what did the `ln` command create? If it IS a symlink, how in the world are you supposed to know or determine that?

4 Upvotes

3 comments sorted by

4

u/candy49997 47m ago edited 44m ago

ln -s is what makes symlinks. ln without -s makes a hardlink.

That's what the 2 in the output of ls -l is telling you; 2 different files point to the same underlying data.

1

u/mabee_steve 21m ago

Thank you! Hardlink is a cool concept, I wasn't aware of it. Not sure when I'd use it, but cool nonetheless.
Renamed the original hardlink with a -2 and re-ran the ls command:

-rw-rw-r-- 2 steve steve 45942 Dec  3 09:33 'Notes Scratchpad-2.txt'
lrwxrwxrwx 1 steve steve    51 Dec  3 10:18 'Notes Scratchpad.txt' -> '/home/steve/Documents/Notes Scratchpad.txt'

1

u/chuggerguy Linux Mint 22.3 Zena | MATÉ 15m ago

u/candy49997 explains it well.

One way to tell that an icon on your desktop is only a sym/soft link to the actual file is that it should have some sort of emblem such as an arrow.

Below you can see my "cameras" folder is a soft link that only points to the real folder which lives on another drive. (even has a different name)

One good thing about a soft link is they take up negligible space. Plus if you decide you no longer need the link sitting on your desktop, you can just delete the link and the file/s it points to remains. You can't do that with a hard link. Delete one of the hard links that point to the actual file and the actual file goes away.

Have fun.