chown: invalid option -- 'i' Try 'chown --help' for more information
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 -- *
Related videos on Youtube
Marco Marsala
Updated on September 18, 2022Comments
-
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 almost 8 yearsYou could try
chown -R myuser:mygroup ./*
-
-
Deadjim almost 8 yearsisn't this the same answer already given by @heemayl?
-
Rinzwind almost 8 years@Kris both answers got posted at almost the same time ;-)
-
Thomas almost 8 yearsYou obfuscated the user and group in your question but not in your answer...
-
UTF-8 almost 8 years@Kris It's rather unlikely he copied the other answer within 39 seconds after it was posed.
-
Jim Driscoll almost 8 yearsPrefixing 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 intochown
,-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 almost 8 yearssorry, I didn't mean to imply such.