Live data from Hacker News

Difference Between a Symbolic Link and a Hard Link

toolhub.tech

11–15 of 15 posts

Re: Difference Between a Symbolic Link and a Hard Link

#11
post #10
post #7

Earlier quoted context omitted.

If it was a hard link to a directory, rm -r could've removed all the files from it first, before removing the directory itself. This would remove everything from the original dir. (Or at least I think so - not a Linux expert here)

What system can you hardlink a directory? At least on macOS and FreeBSD the man pages explicitly state that hard links can only be created on files.

I believe you can do it on Windows.

Re: Difference Between a Symbolic Link and a Hard Link

#12
post #11
post #10

Earlier quoted context omitted.

What system can you hardlink a directory? At least on macOS and FreeBSD the man pages explicitly state that hard links can only be created on files.

I believe you can do it on Windows.

Windows does not allow hardlinks to directories, but it does have the concept of junction points.

https://learn.microsoft.com/en-us/sysinternals/downloads/jun...

Re: Difference Between a Symbolic Link and a Hard Link

#13
post #10
post #7

Earlier quoted context omitted.

If it was a hard link to a directory, rm -r could've removed all the files from it first, before removing the directory itself. This would remove everything from the original dir. (Or at least I think so - not a Linux expert here)

What system can you hardlink a directory? At least on macOS and FreeBSD the man pages explicitly state that hard links can only be created on files.

Nit about macOS: HFS+ supports hard links to directories (added in 10.5 to support Time Machine), but APFS does not.

Re: Difference Between a Symbolic Link and a Hard Link

#14

What made it click for me mentally was this thought: there's no such thing as a hard link . Or alternatively, every file is a hard link . Files don't have names. At least, they don't have names for themselves. Instead, they have unique ids (i-node numbers). But obviously we use names for files, which happens because a directory can give a name to a file. However, the name is just that directory's name for the file. T…

Good explanation and same for me.

I came to that realization when I needed to delete a file and the function call to use was named `unlink`.

Re: Difference Between a Symbolic Link and a Hard Link

#15
post #10

Earlier quoted context omitted.

What system can you hardlink a directory? At least on macOS and FreeBSD the man pages explicitly state that hard links can only be created on files.

Nit about macOS: HFS+ supports hard links to directories (added in 10.5 to support Time Machine), but APFS does not.

Interesting, thanks for the information. I had thought it was the same with HFS but guess it's been some time since I used it...
Post reply on HN