18

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?

1
  • 2
    You could try chown -R myuser:mygroup ./*
    – Kris
    Sep 20, 2016 at 8:26

2 Answers 2

33

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 ./*
1
  • 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. Sep 21, 2016 at 0:07
7

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 -- *

5
  • 4
    isn't this the same answer already given by @heemayl?
    – Kris
    Sep 20, 2016 at 8:37
  • 3
    @Kris both answers got posted at almost the same time ;-)
    – Rinzwind
    Sep 20, 2016 at 8:39
  • 1
    You obfuscated the user and group in your question but not in your answer...
    – Thomas
    Sep 20, 2016 at 11:54
  • 4
    @Kris It's rather unlikely he copied the other answer within 39 seconds after it was posed.
    – UTF-8
    Sep 20, 2016 at 15:07
  • sorry, I didn't mean to imply such.
    – Kris
    Sep 21, 2016 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .