Questions tagged [hardlink]

Links a name with actual data (file). Hard-linking allows the file to have multiple names (handles). Present in POSIX-compliant systems (also only partially!): GNU/Linux, Android, Apple Mac OS X and even Windows, though with limitations. Allows for slightly different aliasing than soft-linking (aka symbolic linking) - there are trade-offs to each methods.

In a nutshell

Files contain data. Filenames point to files. If you have more than one name pointing to the same file, you have a hard link.

Most file systems support hard links, but not all (FAT, for one, doesn't). Usually this means keeping track of the number of distinct filenames used for a particular file; the filesystem then continues to make file content available for access as long as at least one hard link is left. If you ever wondered why C uses unlink to remove files, that's the reason: it doesn't remove the file, it removes the fileNAME and decreases the aforementioned reference counter.

Hard vs soft linking

Two hard links to a given set of content will reference the same inode. In other words, they are different names for the same file. A soft link to a file is a different file (its own inode) which contains data pointing to a target.

MyFile in (say) inode 3333 can have "my text" as its data. MyHardLink will point to the same inode, 3333 and thus will have same data. MySoftLink will be a different file, occupying a different inode (say, 3334) and its data will be a pointer to the name MyFile.

Illuminating and illustrated! explanation of both concepts by Lew Pitcher, from Linux Gazette.

Limitations

Hardlinks cannot point to a parent of the directory containing them. This avoids endless recursion. There is also generally a limit on how many hard links can be made to the same inode, stemming from the reference counter stored by the filesystem; if too many hardlinks were to be created to one inode, the reference count would overflow. These limits are usually are worked around with symbolic links, and are very well described on Wikipedia.

Additional Windows limitations

  1. The minimum client and server Windows OS supporting hardlinks are - correspondingly - XP and Server 2003.
  2. Windows hard links are NTFS-only.
  3. NTFS uses 10 bits for the filename counter, so there can be only 1023 distinct names per file.

MSDN page on Hard Links

Windows API for CreateHardLink function

192 questions
1
vote
1 answer

Is there a way to merge redundant files when preparing a .dmg file?

My company ships a package containing several Qt-based MacOS/X GUI applications; the package ships as a .dmg file, and "installation" consists of double-clicking the .dmg icon, then dragging one or more application icons to where he wants to keep…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
1
vote
2 answers

CreateHardLink() fails on NTFS volume with error code 1 (Incorrect function)

We have a desktop application that makes use of NTFS hard links. The application is distributed and used successfully on over 400K user PCs worldwide. There is one customer however who has CreateHardLink() function fail consistently with error code…
Levi Haskell
  • 795
  • 8
  • 20
1
vote
1 answer

hard link created suddenly on NAND flash

I was surprised by a hard link created suddenly between a config file that I (as usr1) own and a temporary file that I create in an OS daemon (each 5 minutes), to copy from the original config file. After copying back to the original file, I use…
1
vote
4 answers

Programmatically finding the target of a Windows Hard link

I've been playing around a lot recently with manipulating reparse points programmatically, and something's been bugging me for a little while now. Since Windows hard links aren't reparse points like junctions or symbolic links, they can't be…
Charles Grunwald
  • 1,441
  • 18
  • 22
0
votes
1 answer

Git hook for pre-commit being invoked but hardlinks failing

Please look at my answer here: Git and hard links I tried to put the same script in pre-commit, but somehow the hard links are not being created. The script is indeed executed (i.e. an echo inside it proves that). I tried to run the same ln manually…
Niloct
  • 9,491
  • 3
  • 44
  • 57
0
votes
1 answer

Invisible hardlink

I have a small application that displays the contents of a log file, somewhat transmogrified for readability. As the log file gets rewritten occasionally and Windows file system semantics prohibit deletion of open files, I create a hardlink to the…
Simon Richter
  • 28,572
  • 1
  • 42
  • 64
0
votes
0 answers

Understanding "hardlinks" (linux-like) on NTFS

I'm a bit off with the explanation for hardlinks, symlinks and junctions on NTFS. I want to have c:\A\B\C c:\C\B\A be the same directory, just accessible thru to different pathes. So if I put a file in one, it should appear in both but still be one…
rhavin
  • 1,512
  • 1
  • 12
  • 33
0
votes
0 answers

Invalid cross-device link inside same docker volume

I'm running one of NVIDIAs official CUDA docker images with CUDA 12.x installed on it. I want to install another version of cuda in this image as well. When trying to install it using sudo apt install cuda=11.x.y-z, it fails with an Invalid…
ankit
  • 3,328
  • 3
  • 26
  • 39
0
votes
0 answers

Does anaconda support hardlink in Windows?

I use anaconda in Windows11 to management conda environments. However, the environments consume a lot of harddisk, with 20 environment occupying about 50GB. All environments hold their own hard copy of the packages, which have a lot of…
tao.jing
  • 1
  • 2
0
votes
1 answer

.editorConfig in multiple projects with hardlinks

I have a similar scenario as those described here and here: I want to have a single .editorConfig file, but be able to commit it to multiple repos (one to many). I have read that there are some issues with creating softlinks and symlinks on git, but…
Jazz.
  • 458
  • 4
  • 12
0
votes
1 answer

React Native - manage hardlinks/softlinks in iOS

I need to find a tool that allows to create and manage file hardlinks/softlinks in iOS with my React Native app. Though it is a common feature I suprisingly can't find a single package that works with them (don't know if is just because of great…
Vyacheslav Orlovsky
  • 329
  • 1
  • 6
  • 15
0
votes
2 answers

difference between /bin/ls and /usr/bin/ls

It seems that both /bin/ls and /usr/bin/ls have the same inode (and the same sha-256 hash) but the number of hard links displayed by ls -li /usr/bin/ls /bin/ls is 1 instead of 2 : user@debian:~/Documents/Unix$ ls -lai /usr/bin/ls /bin/ls 8258848…
cmdEvo
  • 23
  • 4
0
votes
0 answers

win32 hardlinks and process name

I'm a tester and have hundreds of versions of the same program to test. To avoid copying certain executables I store them as prog.exe.1 prog.exe.2 etc. then the script create a hardlink prog.exe (mklink /H .. or fsutil hardlink create prog.exe…
user2708351
  • 121
  • 7
0
votes
1 answer

Greengrass Error when start Daemon "No hardlink/softlink protection enabled" in Android 7 Nougat Shell

Can't start greengrass daemon core Setting up greengrass daemon Validating hardlink/softlink protection AWS Greengrass detected insecure OS configuration: No hardlink/softlink protection enabled.
0
votes
1 answer

Force a version control not to break hard links when merging/pulling from another repo?

I have a project with some part of the code that are public and other that are not. I have the complete project versioned in my entreprise in folder E, and a specific folder P where I put the public part. I thought it was a good idea to put…
Louis
  • 1,392
  • 2
  • 11
  • 16