Skip to content

chmod: passing multiple modes with leading hyphens. #3147

Closed
dhruv-15-03/Portfolio
#23

Description

@tertsdiepraam

GNU chmod has some... ehh... interesting behaviour when it comes to leading hyphens in the mode:

chmod -w -w f

changes the permissions of f (and not of a file called -w). uutils simply throws an error because it does not expect the flag -w.

On the other hand,

chmod a-w a-w f

does try to change the permissions of a-w and f.

However, this behaviour changes when the -w is passed after --, because

chmod -- -w -w f

tries to modify both -w and f. This case is currently handled correctly in uutils, but I still included it here, because it is likely to break for some naive solutions to this issue.

All this is tested in the chmod/usage.sh tests from GNU. The cases tested there are listed below, where the provided arguments are on the left, followed by a colon and the files that it will try to chmod:

--         :
-- --      :
-- -- -- f : -- f
-- -- -w f : -w f
-- -- f    : f
-- -w      :
-- -w -- f : -- f
-- -w -w f : -w f
-- -w f    : f
-- f       :
-w         :
-w --      :
-w -- -- f : -- f
-w -- -w f : -w f
-w -- f    : f
-w -w      :
-w -w -- f : f
-w -w -w f : f
-w -w f    : f
-w f       : f
f          :
f --       :
f -w       : f
f f        :
u+gr f     :
ug,+x f    :

Activity

  1. sylvestre commented on Mar 11, 2022

    @sylvestre
    SponsorContributor

    Simple testcase:

    touch f
    chmod -w -w -- f 
    ./target/debug/coreutils chmod -w -w -- f 
    
  2. stale commented on Mar 15, 2025

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  3. dhruv-15-03 commented on Aug 3, 2026

    @dhruv-15-03
    Contributor

    Picking this up. The file-selection half of the table already passes on current main (it landed in e982d57, "chmod: fix GNU test 'chmod/usage'"), but the umask diagnostic still diverges: chmod -- -w f warns "new permissions are ..." and exits 1 where GNU is silent and exits 0. I'll send a PR that fixes that and locks all 26 rows of the table down as regression tests so this can be closed with evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions