Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using this command:

chown root:www-data /var/www/example.com -R 

but I get an error message that the directory is not listed.

What is wrong?

share|improve this question
1  
What exact error message do you get? –  Stephane Chazelas May 5 '13 at 13:15
add comment

2 Answers

The GNU coreutils version of chown, which is standard under Ubuntu, accept options placed anywhere, (as long as -- is not used). That is:

chown foo:bar some/location -R
chown -R foo:bar some/location

both work. This is because of how getopt_long() works. In my book this is a bug – as it should either result in error, or be documented, which from what I can find it is not.

chown foo:bar some/location -- -R

would look for directory named -R.


However if one set environment variable POSIXLY_CORRECT the first example would fail if there is no directory named -R, and would never recurse.

$ export POSIXLY_CORRECT=
$ chown -v :foo a/ -R
ownership of `a/' retained as foo:foo
chown: cannot access `-R': No such file or directory

IMHO: always try to conform to the POSIX way as one day you enter that command on another system where a POSIX is enforced, thus breaking.

Also note that the value of POSIXLY_CORRECT has no effect. This would not disable it:

export POSIXLY_CORRECT=0
export POSIXLY_CORRECT=no
export POSIXLY_CORRECT=false
export POSIXLY_CORRECT=...

One would need to unset it.


It could be your system is set up with either another chown tool or POSIXLY_CORRECT is set.

Check by:

export | grep POSIX
chown --version
# etc.

As a side note, the use of dot, ., to separate group and user was obsoleted as of POSIX 2001 (info coreutils 'chown invocation'), but still supported for backwards compatibility, though it is not recommended.

share|improve this answer
add comment

You have to put the -R option in front.

chown -R root:www-data /var/www/example.com 

(I always use a dot instead of a colon between user and group, but the man pages says the colon should be used).

share|improve this answer
    
Er, I don't know why you think you can't use a colon: sprunge.us/aDJW –  Chris Down May 5 '13 at 8:55
1  
Dot was the old way and colon the new. Guess someone thought it'd be nice to be able to use dots in user-names/groups. –  Sukminder May 5 '13 at 9:05
    
@Sukminder I guess that 'old way' identifies me. I am glad that dot is still allowed as it is difficult to change typing habits after using the command this way for close to 30 years –  Anthon May 5 '13 at 9:09
    
@Sukminder At one point Anthon said in his answer that colons were not allowed, which is not true. I wasn't trying to suggest that using a dot is "wrong" in some way, just that a colon is perfectly valid. –  Chris Down May 5 '13 at 9:24
    
GNU tools allow options after arguments (which IMO is a bug) unless the POSIXLY_CORRECT environment variable is set (or -- is used to mark the end of options). AFAIK, Ubuntu does not set that option in the default environment, so I doubt this be the issue. Anyway I agree one should put the options in front. –  Stephane Chazelas May 5 '13 at 13:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.