Share to: share facebook share twitter share wa share telegram print page

Hard link

In computing, a hard link is a directory entry (in a directory-based file system) that associates a name with a file. Thus, each file must have at least one hard link. Creating additional hard links for a file makes the contents of that file accessible via additional paths (i.e., via different names or in different directories).[1] This causes an alias effect: a process can open the file by any one of its paths and change its content. By contrast, a soft link or “shortcut” to a file is not a direct link to the data itself, but rather a reference to a hard link or another soft link.

Every directory is itself a special file on many systems, containing a list of file names instead of other data. Hence, multiple hard links to directories are possible, which could create a circular directory structure, rather than a branching structure like a tree. For that reason, some file systems forbid the creation of additional hard links to directories.

POSIX-compliant operating systems, such as Linux, Android, macOS, and the Windows NT family,[2] support multiple hard links to the same file, depending on the file system. For instance, NTFS and ReFS support hard links,[3] while FAT does not.

Operation

An illustration of the concept of hard linking

Let two hard links, named "LINK A.TXT" and "LINK B.TXT", point to the same physical data. A text editor opens "LINK A.TXT", modifies it and saves it. When the editor (or any other app) opens "LINK B.TXT", it can see those changes made to "LINK A.TXT", since both file names point to the same data. So from a user's point of view this is one file with several filenames. Editing any filename modifies "all" files, however deleting "any" filename except the last one keeps the file around.

However, some editors, such as GNU Emacs, break the hard link concept. When opening a file for editing, e.g., "LINK B.TXT", emacs renames "LINK B.TXT" to "LINK B.TXT~", loads "LINK B.TXT~" into the editor, and saves the modified contents to a newly created "LINK B.TXT". Now, "LINK A.TXT" and "LINK B.TXT" no longer shares the same data. (This behavior can be changed using the emacs variable backup-by-copying.)

Any number of hard links to the physical data may be created. To access the data, a user only needs to specify the name of any existing link; the operating system will resolve the location of the actual data. Even if the user deletes one of the hard links, the data is still accessible through any other link that remains. Once the user deletes all of the links, if no process has the file open, the operating system frees the disk space that the file once occupied.

Reference counting

Simplified illustration of hard links on typical Unix filesystem. Note that files "A" and "D" both point to same index entry in filesystem's inode table, making its reference count 2.

Most file systems that support hard links use reference counting. The system stores an integer value with each logical data section that represents the total number of hard links that have been created to point to the data. When a new link is created, this value is increased by one. When a link is removed, the value is decreased by one. When the counter becomes zero, the operating system frees the logical data section. (The OS may not to do so immediately, e.g., when there are outstanding file handles open, for performance reasons, or to enable the undelete command.)

This is a simple method for the file system to track the use of a given area of storage, as zero values indicate free space and nonzero values indicate used space. The maintenance of this value guarantees that there will be no dangling hard links pointing nowhere. The data section and the associated inode are preserved as long as a single hard link (directory reference) points to it or any process keeps the associated file open.

On POSIX-compliant operating systems, the reference count for a file or directory is returned by the stat() or fstat() system calls in the st_nlink field of struct stat.

Limitations

To prevent loops in the filesystem, and to keep the interpretation of the ".." file (parent directory) consistent, operating systems do not generally allow hard links to directories. UNIX System V allowed them, but only the superuser had permission to make such links.[4] Mac OS X v10.5 (Leopard) and newer use hard links on directories for the Time Machine backup mechanism only.[5]

Hard links can be created to files only on the same volume, i.e., within the same file system. (Different volumes may have different file systems. There is no guarantee that the target volume's file system is compatible with hard linking.)

The maximum number of hard links to a single file is limited by the size of the reference counter. On Unix-like systems the counter is 4,294,967,295 (on 32-bit machines) or 18,446,744,073,709,551,615 (on 64-bit machines). In some file systems, the number of hard links is limited more strictly by their on-disk format. For example, as of Linux 3.11, the ext4 file system limits the number of hard links on a file to 65,000.[6] Windows limits enforces a limit of 1024 hard links to a file on NTFS volumes.[7]

On Linux Weekly News, Neil Brown criticized hard links as high-maintenance, since they complicate the design of programs that handle directory trees, including archivers and disk usage tools. These apps must take care to de-duplicate files that are linked multiple times in a hierarchy. Brown notes that Plan 9 from Bell Labs, the intended successor to Unix, does not include the concept of a hard link.[8]

Platform support

Windows NT 3.1 and later support hard links on the NTFS file system.[9] Windows 2000 introduces a CreateHardLink() function to create hard links, but only for files, not directories.[10] The DeleteFile() function can remove them.

To create a hard link on Windows, end-users can use:

To interrogate a file for its hard links, end-users can use:

  • The fsutil utility[11]
  • The Get-Item and Get-ChildItem cmdlets of PowerShell. These cmdlets represent each file with an object; PowerShell adds a read-only LinkType property to each of them. This property contains the "HardLink" string if the associated file has multiple hard links.[14]

The Windows Component Store uses hard links to keep track of different versions of components stored on the hard disk drive.

On Unix-like systems, the link() system call can create additional hard links to existing files. To create hard links, end-users can use:

  • The ln utility
  • The link utility
  • The New-Item cmdlet of PowerShell[13]

To interrogate a file for its hard links, end-users can use:

  • The stat command
  • The ls -l command
  • The Get-Item and Get-ChildItem cmdlets of PowerShell (see above)[14]

Unix-like emulation or compatibility software running on Microsoft Windows, such as Cygwin and Subsystem for UNIX-based Applications, allow the use of POSIX interfaces.

OpenVMS supports hard links on the ODS-5 file system.[15] Unlike Unix, VMS can create hard links to directories.

See also

  • Symbolic link: Points to a hard link, not the file data itself; hence, it works across volumes and file systems.
  • NTFS links: Details the four link types that the NTFS supports—hard links, symbolic links, junction points, and volume mount points
  • Shortcut: A small file that points to another in a local or remote location
    • Alias: macOS implementation of a shortcut
    • Shadow: OS/2 implementation of a shortcut
  • freedup – The freedup command frees-up disk space by replacing duplicate data stores with automatically generated hard links

References

  1. ^ Pitcher, Lew. "Q & A: The difference between hard and soft links".
  2. ^ "Link Shell Extension".
  3. ^ "Resilient File System (ReFS) overview". Microsoft Learn. 26 October 2022 – via Microsoft Docs.
  4. ^ Bach, Maurice J. (1986). The Design of the UNIX Operating System. Prentice Hall. p. 128. ISBN 9780132017992.
  5. ^ Pond, James (August 31, 2013). "How Time Machine Works its Magic". File System Event Store, Hard Links. Archived from the original on June 21, 2019. Retrieved May 19, 2019.
  6. ^ "Linux kernel source tree, fs/ext4/ext4.h, line 229".
  7. ^ "CreateHardLinkA function (winbase.h)". Windows App Development. 13 October 2021 – via Microsoft Docs.
  8. ^ Brown, Neil (23 November 2010). "Ghosts of Unix past, part 4: High-maintenance designs". Linux Weekly News. Retrieved 20 April 2014.
  9. ^ "How hard links work". Microsoft Docs. 6 January 2011.
  10. ^ "CreateHardLink Function". Windows Development. Microsoft. 10 March 2011. Archived from the original on 2 July 2011 – via MSDN. Establishes a hard link between an existing file and a new file. This function is only supported on the NTFS file system, and only for files, not directories.{{cite web}}: CS1 maint: unfit URL (link)
  11. ^ a b "Fsutil hardlink". Windows App Development. Microsoft. 18 April 2012 – via Microsoft Docs.
  12. ^ "Mklink". Microsoft Docs. Microsoft. 18 April 2012.
  13. ^ a b "New-Item (PowerShell 3.0)". Microsoft Docs. Microsoft. 22 June 2020. If your location is in a FileSystem drive, the following values are allowed: If your location is in a FileSystem drive, the following values are allowed: File[,] Directory[,] Junction[,] HardLink
  14. ^ a b "FileSystemProvider.cs". PowerShell / PowerShell repo. Microsoft. 20 November 2021. Lines 8139–8234 – via GitHub.
  15. ^ "OpenVMS System Manager's Manual, Vol. I" (PDF). VSI. August 2019. Retrieved 2021-01-23.

Read other articles:

Irish-born Colonel Colonel Blood redirects here. For other uses, see Colonel Blood (disambiguation). Blood in an 1813 illustration Colonel Thomas Blood (1618 – 24 August 1680) was an Anglo-Irish officer and self-styled colonel best known for his attempt to steal the Crown Jewels of England from the Tower of London in 1671.[1] Described in an American source as a noted bravo and desperado,[2] he was also known for his attempt to kidnap and, later, to kill, his enemy Jame...

برنامج تنمية القدرات البشريةالشعارمعلومات عامةالتأسيس 15 سبتمبر 2021المقر الرئيسي السعوديةالمنظومة الاقتصاديةمناطق الخدمة  السعوديةتعديل - تعديل مصدري - تعديل ويكي بيانات برنامج تنمية القدرات البشرية هو أحد برامج تحقيق رؤية السعودية 2030، أطلقه ولي العهد الأمير محمد بن سل

Kinich Ahau as a ruler, Classic period Kinich Ahau[pronunciation?] (Kʼinich Ajaw) is the 16th-century Yucatec name of the Maya sun god, designated as God G when referring to the codices. In the Classic period, God G is depicted as a middle-aged man with an aquiline nose, large square eyes, cross-eyed, and a filed incisor in the upper row of teeth. Usually, there is a k'in ('sun')-infix, sometimes in the very eyes. Among the southern Lacandons, Kinich Ahau continued to play a role in ...

هيئة الإسعاف المصرية هيئة الإسعاف المصريةالشعار البلد  مصر المقر الرئيسي السادس من أكتوبر، محافظة الجيزة تاريخ التأسيس 1902 (منذ 121 سنة) المالك وزارة الصحة والسكان النوع هيئة حكومية منطقة الخدمة مصر اللغات الرسمية العربية الرئيس عمرو رشيد[1] الموقع الرسمي Ambulance.Organization...

BSD LinkDidirikan2017LokalBumi Serpong DamaiWilayah layananKabupaten Tangerang, Kota Tangerang SelatanJenis layananAngkutan cepat busRute6 koridorOperatorLorenaSitus webbsdcity.com/access/shuttle-bus-bus-station BSD Link adalah bus yang melayani warga yang berpergian dari/menuju kompleks perumahan Bumi Serpong Damai (BSD), Banten dan sekitarnya. Bus ini memiliki rute yang mengitari kawasan Bumi Serpong Damai yang masuk dua kecamatan, yakni Serpong, Tangerang Selatan dan Cisauk, Tangerang. Sej...

El impuesto sobre hidrocarburos o impuesto sobre combustible es un impuesto especial e indirecto que grava el consumo de cualquier hidrocarburo utilizado como combustible y de cualquier producto utilizado como carburante. Es decir, grava los productos utilizados, por ejemplo, en calefacción (combustible) y en el uso de motores (carburante).[1]​ Implementación a nivel mundial Refinería Shell en California. Bolivia El 17 de mayo de 2005 mediante Ley 3058 se aprobó en Bolivia la ley de...

Portal Geschichte | Portal Biografien | Aktuelle Ereignisse | Jahreskalender | Tagesartikel ◄ | 13. Jahrhundert | 14. Jahrhundert | 15. Jahrhundert | ► ◄ | 1270er | 1280er | 1290er | 1300er | 1310er | 1320er | 1330er | ► ◄◄ | ◄ | 1300 | 1301 | 1302 | 1303 | 1304 | 1305 | 1306 | 1307 | 1308 | ► | ►► Staatsoberhäupter · Nekrolog Kalenderübersicht 1304 Januar Kw Mo Di Mi Do Fr Sa So 1     1 2 3 4 5 2 6 7 8 9 10 11 12 3...

Iglesia de Los Dominicos Monumento Histórico(Decreto Supremo n.º 1296, del 15 de noviembre de 1983) Fachada de la iglesia.LocalizaciónPaís Chile ChileDivisión Región Metropolitana de SantiagoSubdivisión Provincia de SantiagoLocalidad Las CondesDirección Av. Apoquindo 9085Coordenadas 33°24′27″S 70°32′30″O / -33.40758333, -70.54175278Información religiosaCulto Iglesia católicaArquidiócesis Santiago de ChileOrden Orden de PredicadoresAdvocación San Vice...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أغسطس 2022) تمثيل بصري لثقب شوارزشيلد الدودي. لم يتم رصد الثقوب الدودية أبداً، لكن تم تنبؤ وجودها من خلال نماذج رياضية ونظريات علمية. في الفيزياء النظرية، يتكون التباين ا

Aeroportos internacionais na Alemanha Tráfego aéreo doméstico alemão por número de voos Esta é uma lista dos principais aeroportos da Alemanha, classificados por cidade.[1][2] [3] Cidade ICAO IATA Nome do aeroporto Aeroportos civis Altenburg EDAC AOC Aeroporto de Altenburg-Nobitz Baden-Baden/Karlsruhe EDSB FKB Aeroparque de Baden Bayreuth EDQD BYU Aeroporto Bindlacher Berg (Aeroporto de Bayreuth) Berlim EDDB BER Aeroporto de Berlim-Brandemburgo Berlim EDDB SXF Aeroporto de Berlim-Schön...

The topic of this article may not meet Wikipedia's notability guideline for stand-alone lists. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be merged, redirected, or deleted.Find sources: List of current airships in the United States – news · newspapers · books...

Munisipalitas Log-Dragomer Občina Log - DragomerMunisipalitasLokasi di SloveniaNegara SloveniaLuas • Total11 km2 (4 sq mi)Populasi (2013) • Total3.660 • Kepadatan330/km2 (860/sq mi)Kode ISO 3166-2SI-208Situs webhttp://www.log-dragomer.si/ Munisipalitas Log-Dragomer adalah salah satu dari 212 munisipalitas di Slovenia. Kode ISO 3166-2 munisipalitas ini adalah SI-208. Menurut sensus 2013, jumlah penduduk munisipalitas yang luasn...

List of Federal Roads in Malaysia Peninsular Malaysia Main Federal Roads Highway shield Name[1] Name of Roads/Highways Highways Part of Asian Highway Network FT 1 Malaysia Federal Route 1 North–SouthBukit Kayu Hitam–Johor Bahru North–South Expressway Northern Route North–South Expressway Northern RouteDarul Aman HighwaySultan Abdul Halim Highway Butterworth Outer Ring Road Butterworth Outer Ring RoadButterworth–Juru HighwayTanjung Malim–Slim River HighwayRawang BypassKuala...

Piru LoveCover art of the CD singleSong by Bloods & Cripsfrom the album Bangin' on Wax ReleasedMarch 9, 1993GenreGangsta rapLabelDangerous RecordsProducer(s)Ron Phillips (executive producer) J. Stank (producer) Piru Love is a song from the 1993 album Bangin' on Wax by the gangsta rap group Blood & Crips.[1] It was subsequently released as a single, along with several alternate versions of the song.[2] It is the group's most popular single.[3] Composition The so...

Village in Greater Poland Voivodeship, PolandŁyczynVillageŁyczynCoordinates: 51°56′N 18°9′E / 51.933°N 18.150°E / 51.933; 18.150Country PolandVoivodeshipGreater PolandCountyKaliszGminaStawiszyn Łyczyn [ˈwɨt͡ʂɨn] is a village in the administrative district of Gmina Stawiszyn, within Kalisz County, Greater Poland Voivodeship, in west-central Poland.[1] It lies approximately 4 kilometres (2 mi) north-east of Stawiszyn, 21 km (13 ...

Sarah Jessica ParkerPekerjaanAktrisProduserTahun aktif1974–sekarangSuami/istriMatthew Broderick (1997–sekarang) Sarah Jessica Parker (lahir 25 Maret 1965) merupakan seorang aktris berkebangsaan Amerika Serikat. Dia menjadi yang terkenal saat diperankan sebagai Carrie Bradshaw di serial TV HBO, Sex and the City. Dia memenangkan empat Golden Globe Awards dan dua Emmy Awards. Dilahirkan di Nelsonville, Ohio. Berkarier di dunia film sejak tahun 1982. Filmografi Tahun Judul Sebagai Catata...

American interior designer (1827–1923) Candace WheelerBornCandace Thurber(1827-03-27)March 27, 1827Delhi, New York, U.S.DiedAugust 5, 1923(1923-08-05) (aged 96)EducationDelaware AcademyOccupationInterior decoratorSpouseThomas Mason WheelerChildren4, including Dora Wheeler KeithParent(s)Abner Gilman ThurberLucy DunhamRelativesHenry L. Stimson (grandson) Candace Wheeler (née Thurber; March 24, 1827 – August 5, 1923), traditionally credited as the mother of interior design, was one of ...

Cycle route in Wales Marker on the Celtic Trail cycle route (National Cycle Network 47) The Celtic Trail is a network of dedicated cycle routes in the National Cycle Network, crossing West, South and Mid Wales, and covering 377 miles in total. It is divided into east and west sections. The west section links Pembroke and Fishguard on the west coast to Swansea, and the east section covers the area from Swansea to Chepstow, Abergavenny and Hay-on-Wye in the east. It is largely traffic free but ...

Main antagonist of LazyTown This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Robbie Rotten – news · newspapers · books · scholar · JSTOR (September 2022) (Learn how and when to remove this template message) Fictional character Robbie RottenLazyTown characterFirst appearanceGlanni Glæpur í Latabæ (1999)Last...

Protein-coding gene in the species Homo sapiens TRPV5IdentifiersAliasesTRPV5, CAT2, ECAC1, OTRPC3, transient receptor potential cation channel subfamily V member 5External IDsOMIM: 606679 MGI: 2429764 HomoloGene: 10520 GeneCards: TRPV5 Gene location (Human)Chr.Chromosome 7 (human)[1]Band7q34Start142,908,101 bp[1]End142,933,746 bp[1]Gene location (Mouse)Chr.Chromosome 6 (mouse)[2]Band6|6 B2.1Start41,629,107 bp[2]End41,657,703 bp[2]RNA expres...

Kembali kehalaman sebelumnya