On this page
  1. os.link
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.link

Prev: os.kill | Up: os | Next: os.listdir
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.link
Tags: #public #python3 #stdlib #os


Import

import os
from os import link

Signature & Overview

os.link(...)

Create a hard link to a file.

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    src = Path(tmp) / "orig.txt"
    dst = Path(tmp) / "hardlink.txt"
    src.write_text("shared", encoding="utf-8")
    os.link(src, dst)
    assert src.stat().st_ino == dst.stat().st_ino

Gotchas

REPL Inspect

from os import link
help(link)

Linked from

Related notes