Hi there,
I need to change all files/dirs
- all files with 744
- all dirs with 755
is there a script for that ?
thanks,
thegunman
Hi there,
I need to change all files/dirs
is there a script for that ?
thanks,
thegunman
Use find with the -type d option to find directories, and find again with the -type f option to find files. The -exec option of find can be used to run chmod.
Presuming you mean all files with 644 (not 744) and all dirs 755, this should work:
chmod -R a=r,a+X,u+w /path/to/dir
Hi, Mr. S.
Aren't you slightly assuming that everything has the umask default?
Hi Mr. Moderator (
),
IMO this should work whatever your umask is set to. Note I did make a small modification, otherwise files that were already executable would keep their execute permissions.
S.
Thank you 
I don't doubt you - I never would, and my umask analysis (although wrong) looked that way because of the files in my directory at the time that didn't seem to change.
I did a wee test:
$ cd Test
$ touch a b c
$ ll
total 0
drwxr-xr-x 5 scott staff 170 Dec 16 23:18 .
drwxr-xr-x 8 scott staff 272 Dec 16 23:12 ..
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 a
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 b
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 c
$ chmod 000 a
$ chmod 777 . c
$ ll
total 0
drwxrwxrwx 5 scott staff 170 Dec 16 23:18 .
drwxr-xr-x 8 scott staff 272 Dec 16 23:12 ..
---------- 1 scott staff 0 Dec 16 23:18 a
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 b
-rwxrwxrwx 1 scott staff 0 Dec 16 23:18 c
$ cd ..
$ chmod -R a=r,a+X,u+w Test
$ ll Test
drwxr-xr-x 5 scott staff 170 Dec 16 23:18 .
drwxr-xr-x 8 scott staff 272 Dec 16 23:12 ..
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 a
-rw-r--r-- 1 scott staff 0 Dec 16 23:18 b
-rwxr-xr-x 1 scott staff 0 Dec 16 23:18 c
This is strange, on my host I get different results:
$ ls -la chmodtest/
total 28
drwxr-xr-x 6 unixuser unixuser 4096 2009-12-16 23:37 .
drwxr-xr-x 237 unixuser unixuser 8192 2009-12-16 22:44 ..
d--------- 2 unixuser unixuser 4096 2009-12-16 22:44 a
drwxr-xr-x 2 unixuser unixuser 4096 2009-12-16 22:44 b
drwxr-xr-x 3 unixuser unixuser 4096 2009-12-16 23:01 c
drwxr-xr-x 2 unixuser unixuser 4096 2009-12-16 22:44 d
---------- 1 unixuser unixuser 0 2009-12-16 23:37 x
-rw-r--r-- 1 unixuser unixuser 0 2009-12-16 23:37 y
-rwxrwxrwx 1 unixuser unixuser 0 2009-12-16 23:37 z
$ chmod -R a=r,a+X,u+w chmodtest/
$ ls -la chmodtest/
total 28
drwxr-xr-x 6 unixuser unixuser 4096 2009-12-16 23:37 .
drwxr-xr-x 237 unixuser unixuser 8192 2009-12-16 22:44 ..
drwxr-xr-x 2 unixuser unixuser 4096 2009-12-16 22:44 a
drwxr-xr-x 2 unixuser unixuser 4096 2009-12-16 22:44 b
drwxr-xr-x 3 unixuser unixuser 4096 2009-12-16 23:01 c
drwxr-xr-x 2 unixuser unixuser 4096 2009-12-16 22:44 d
-rw-r--r-- 1 unixuser unixuser 0 2009-12-16 23:37 x
-rw-r--r-- 1 unixuser unixuser 0 2009-12-16 23:37 y
-rw-r--r-- 1 unixuser unixuser 0 2009-12-16 23:37 z
I would tend think my platform responds as expected. I am puzzled by your file c . Could it be your chmod has a bug?
That is interesting.
I'm using FreeBSD (Snow Leopard).
Just fired up Linux, and on that I get the result you did.
Interesting indeed. I am wondering is this gives any different results:
chmod -R a=,a+rX,u+w /path/to/dir
It should behave the same.
The result is the same.
Best leave it there. Put it down to a BSD "feature" for now 
#!/bin/bash
path="/path"
gnu_find $path -printf "chmod %m %p\n" > backup.chown
gnu_find $path -type d -exec chmod 755 "{}" \;
gnu_find $path -type f -exec chmod 644 "{}" \;
Scottn/Scrutinizer/ichigo -
Thanks a lot for all your helps !!
Turns out ichigo's command works the best for me...I am a little confused about the command "chmod -R a=rX, u+w ..." not sure why that would create a different permissions rw_ for file and rwx for dirs on the owner's portion bits though...
thegunman
That is because of the capital letter X. See man chmod.
(Quote trimmed to highlight the relevant bits)
It isn't. The final mode for 'z' does not conform to the posix/opengroup spec; it should be -rwxr-xr-x (as per scottn's "c" file).
From chmod:
The key word being "unmodified". Perhaps your chmod's implementation is using the file mode as modified by the first action (a=r) when evaluating "a+X".
Regards,
alister