chown: invalid option -- 'i' Try 'chown --help' for more information

8,379

Solution 1

As the glob (pathname) expansion is done first by the shell before the chown runs, the glob pattern * is expanded to all files in the current directory first and chown is getting those as its options and arguments. You have a file in the current directory that starts with -i, hence chown is considering it as an option, not as an argument (filename).

You need to use -- to indicate the end of options for chown:

chown -R myuser:mygroup -- *

Or precede the glob pattern (*) with ./ to explicitly indicate it as argument:

chown -R myuser:mygroup ./*

Solution 2

The issue was a file named -index.php in the folder, so chown interpreted it as a command line option.

The solution was using the double-hyphens chown -R myuser:mygroup -- *

Share:
8,379

Related videos on Youtube

Marco Marsala
Author by

Marco Marsala

Updated on September 18, 2022

Comments

  • Marco Marsala
    Marco Marsala almost 2 years

    I have a strange issue with the following command:

    # chown -R myuser:mygroup *
    chown: invalid option -- 'i'
    Try 'chown --help' for more information.
    

    the command is not aliases

    # type chown
    chown is hashed (/bin/chown)
    

    Where I can look further?

    • Admin
      Admin almost 8 years
      You could try chown -R myuser:mygroup ./*
  • Deadjim
    Deadjim almost 8 years
    isn't this the same answer already given by @heemayl?
  • Rinzwind
    Rinzwind almost 8 years
    @Kris both answers got posted at almost the same time ;-)
  • Thomas
    Thomas almost 8 years
    You obfuscated the user and group in your question but not in your answer...
  • UTF-8
    UTF-8 almost 8 years
    @Kris It's rather unlikely he copied the other answer within 39 seconds after it was posed.
  • Jim Driscoll
    Jim Driscoll almost 8 years
    Prefixing with ./ doesn't mean that it's an argument (meaning filename here), but it does mean that none of the expanded names will look like an option (starting with "-"). When the shell sees a line like chown -R myuser:mygroup ./*, it splits it into chown, -R, myuser:mygroup, ./* and then replaces glob patterns with the corresponding filesystem paths, eg. chown, -R, myuser:mygroup, ./-index.html, ./favicon.ico, ./My -ve Numbers. Since chown only looks for the first character being a dash when looking for option args, it will presume that those are positional args.
  • Deadjim
    Deadjim almost 8 years
    sorry, I didn't mean to imply such.