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?

heemayl
  • 90,425
  • 20
  • 200
  • 267
Marco Marsala
  • 353
  • 2
  • 8

2 Answers2

32

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 ./*
heemayl
  • 90,425
  • 20
  • 200
  • 267
  • 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. – Jim Driscoll Sep 21 '16 at 00: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 -- *

Marco Marsala
  • 353
  • 2
  • 8