Skip to content

cp -l changes the mode of the source file #15087

Closed

Description

@abendrothj

cp -l should only create a hard link. uutils cp also applies a mode to the destination afterwards, and since the link shares the source's inode, the source file's mode changes too. GNU cp leaves the file's mode alone.

With umask 077:

$ echo a > src; chmod 755 src
$ (umask 077; cp -l src lnk); stat -c '%a %n' src lnk

GNU coreutils 9.12:

755 src
755 lnk

uutils main:

700 src
700 lnk

The same happens with cp -lf, cp -l --backup, cp -lp/cp -la and cp -rl.

cp -l silently changes the permissions of the original file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions