On this page
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
- Hard link (same filesystem only, files only): Unlike
os.symlink(), hard links cannot cross mount points or point to directories.
REPL Inspect
from os import link
help(link)
Linked from
Related notes
- tuts/python3/stdlib_module/os/kill Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/listdir Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib