GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Clarify os.link behavior with follow_symlinks=True on POSIX systems · Issue #138623 · python/cpython

Clarify os.link behavior with follow_symlinks=True on POSIX systems #138623

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
Clarify os.link behavior with follow_symlinks=True on POSIX systems#138623
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided

Description

@guanjiesun
guanjiesun
opened on Sep 7, 2025
Issue body actions

Software environemnt

  • Python info: Python 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:27:50) [GCC 13.3.0]
  • OS info: Linux ubuntu 6.8.0-78-generic

A small problem I found in the document about os.link function

The current documentation for os.link states:

If follow_symlinks is False, and the last element of src is a symbolic link,
link will create a link to the symbolic link itself instead of the file the link points to.

This wording suggests that if follow_symlinks=True (the default), the call will follow
the symlink and create a hard link to the target file.

However, on POSIX systems (e.g., Linux), this is not what actually happens.
The underlying link(2) system call never follows symbolic links — it always creates
a hard link to the symlink itself. As a result, on Linux, whether follow_symlinks is True or False, the result is the same.

os.link("symlink", "dst")
os.link("symlink", "dst", follow_symlinks=False)

A simple experiment

Experiment result is presented as below. shell.py is a regular file and soft is the symbolic link to shell.py. soft, link-with-true, link-with-false have the same inode and they are all softlinks to shell.py.

Image

Suggested documentation update

To avoid confusion, please update the os.link documentation to note that:

  • On POSIX systems (such as Linux), the underlying link(2) system call never follows symbolic links.
  • Therefore, follow_symlinks=True and follow_symlinks=False behave the same: both create a hard link to the symlink itself, not to its target.
  • If users want to create a hard link to the target of a symlink, they need to resolve it first with os.readlink().

Activity

  1. guanjiesun
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Sep 7, 2025
  2. github-project-automation
    added this to docs issueson Sep 7, 2025
  3. github-project-automation
    moved this to Todo in docs issueson Sep 7, 2025
  4. serhiy-storchaka commented on Sep 7, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Sep 7, 2025
    Member
    More actions

    This is a duplicate of #81793, which was fixed 4 month ago. Wait for Python 3.14.

  5. StanFromIreland
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Sep 7, 2025
  6. picnixz
    closed this as a duplicateof os.link(..., follow_symlinks=True) broken on Linux #81793 on Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dirpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided

    Projects

    • docs issues
      Status
      Todo
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.