# chmod behavioral question



## nicols (Feb 19, 2009)

I upgraded my server from FreeBSD 4.10 to FreeBSD 6.2 and found that the chmod command is acting differently since the change. :\

~FreeBSD 6.2~
%mkdir testfolder
%chmod -R 755 testfolder/
%chmod -R 644 testfolder/
%chmod -R 755 testfolder/
chmod: testfolder/: Permission denied 

~FreeBSD 4.10~
%mkdir testfolder
%chmod -R 755 testfolder/
%chmod -R 644 testfolder/
%chmod -R 755 testfolder/
% ls -lah | grep testfolder
drwxr-xr-x  2 nicols  vuser  512B Feb 19 01:24 testfolder


Is there a behavioral difference I'm missing?

I found the default umask to be the same in both:
FreeBSD 6.2 default umask=022 
FreeBSD 4.10 default umask=022
(in case that's pertinent)


----------



## anomie (Feb 19, 2009)

FWIW, I can confirm / recreate that behavior on FBSD 6. 


```
> uname -rms
FreeBSD 6.4-RELEASE-p1 i386
> mkdir foo
> touch foo/bar
> chmod -R 755 foo
> chmod -R 644 foo
> chmod -R 755 foo
chmod: foo/bar: Permission denied
chmod: foo: Permission denied
> ls -ld foo
drw-r--r--  2 mrbig  mrbig  512 Feb 18 22:22 foo
```

Instead, just do like this (picking up where we left off above): 

```
> chmod 755 foo
> chmod -R 755 foo
```

Voila. 

I can't explain the difference to you (and I don't have a FBSD 4 box to compare with). A reasonable WAG might be that chmod is recursively applying permissions lower in the hierarcy on up for some reason.

-------

edit: My CentOS (Linux) server behaves differently still. 


```
[fugu ~]$ rm -r foo/
[fugu ~]$ mkdir foo
[fugu ~]$ touch foo/bar
[fugu ~]$ chmod -R 755 foo
[fugu ~]$ chmod -R 644 foo
chmod: `foo': Permission denied
```

Eh? So maybe you shouldn't be messing around with the execute bit on your directory.  Any reason you're doing that?


----------



## Mel_Flynn (Feb 19, 2009)

I never knew that behavior was broken under 4.x as I've never needed it. Only root is allowed to ignore execute bit on directories. The 6.x behavior is correct.


----------

