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
0
votes
3 answers

Is creating hardlinks from linux on a ntfs partition viable?

I have found a program that can make you save space by hardlinking files that are actually the same, thus leaving only one copy of the file on the file system with more than one hardlink pointing to it. The program is called hardlink. This is very…
Morlock
  • 6,880
  • 16
  • 43
  • 50
0
votes
1 answer

Accelerate/parallelize massive hard-linking loop

I'm working on a script that generates a folder containing several thousand binaries that are to be bundled into multiple installers for different products. One massive part of the script "copies" files from various arbitrary locations to a…
Cloud
  • 18,753
  • 15
  • 79
  • 153
0
votes
0 answers

MySQL : Deleting a folder as well as all it's subfolders

According to the following database schema. What is the most effective solution for deleting a folder as well as all it's subfolders and subfiles using MySQL 6?
user6178502
  • 715
  • 1
  • 5
  • 7
0
votes
0 answers

how does android 'sandbox' restriction work with file 'hardlink'

On Android, every app has its own internal storage and supposed to be only accessible through the same app. What would happen if someone creates an unix 'hard link' in different app to point to the app's internal file (if he knows the file name and…
lannyf
  • 9,865
  • 12
  • 70
  • 152
0
votes
1 answer

emacs is not breaking hard links for hg-controlled files

I have a set of mercurial clones that I created by making one clone of a master repo, then using cp -rlp to make copies of it. My expectation was that I could use them independently, since I use emacs with its default settings, so it ought to be…
sfink
  • 1,726
  • 1
  • 17
  • 22
0
votes
1 answer

Creating a hard link of a directory in java for windows

I've to create in a directory a hard link to a other directory in my java program. (so not a link to a file) I used https://docs.oracle.com/javase/tutorial/essential/io/links.html but it don't work. thanks for your help :) private static void…
0
votes
1 answer

Links,Hardlinks and Symbolic Links: Have all the files from one folder with custom files aswell

I have multiple sites that have common product images and also their own custom ones (with same names). I want to have a folder for each site that has these contents merged but obviously don't want copies of the common images and if a new images is…
Math3w
  • 17
  • 1
  • 7
0
votes
0 answers

How to handle a hardlink with php?

I have a hardlink (created with the php link() function) on my server that is named looksLikeAdirectoryButReallyIsPHPfile and it is linked to aRealDir/index.php looksLikeAdirectoryButReallyIsPHPfile and aRealDir are in the root directory for the web…
user3186555
0
votes
0 answers

Hardlinks and DLLs

I have a shared DLL that I would like to expose as multiple different DLLs with different names in different directories. I figured using hardlinks would work and that running each one would be a different memory space, but from testing it out, it…
0
votes
1 answer

How to make pimcre menu open items in _blank window using hardlink

I have Pimcore cms which has a menu who consist of many link. Those links is created using hardlink. I want to create such link to some page with link property target="_blank". How can I do this? Can it possible?
0
votes
1 answer

/var/spool/mail and /var/mail/root same inode but just one link count

i found something on my linux systems i don't understand. The files /var/spool/mail/root and /var/mail/root point to the same inode but the link count is 1. This is the same on a ubuntu and a centos server. When i create hardlinks to a file the…
0
votes
1 answer

How to show the file with most hard links in a directory in bash

Does anyone know the specific command for how to show the file with most hard links in a directory on terminal on unix?
0
votes
0 answers

How to create a hard link to a directory or a file using QT on Windows

How to create a hard link to a directory or a file using QT on Windows? QFile can only create shortcut on Windows.
Jerry
  • 1,704
  • 5
  • 20
  • 40
0
votes
1 answer

Proxy a git commit message to nested repo if files are updated

I'm looking for a feature or existing library within git to allow be to do some pretty unorthodox behavior described below. Let's say you have a current working directory that has git initialized. /project /.git A subprojects folder with the…
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
0
votes
1 answer

How to determine the amount of space that comes free when running rm -rf

Here is a nice system-administrator problem I ran into today, perhaps somebody here knows a solution. The problem is quite simple: I want to know, beforehand, how much disk space is freed when performing an rm -rf command on Linux. Notice that…
peter p
  • 131
  • 1
  • 10