Google Groups no longer supports new usenet posts or subscriptions. Historical content remains viewable.
Dismiss

recursive chmod

17 views
Skip to the first unread message

Jean-Yves Baudais

unread,
13 Apr 2017, 12:21:2113/04/2017
to
Hello,

"chmod -R u+w *" change the file mode only for the content of the
directory and the sub-directory in my computer (GNU bash, version
4.3.46(1)-release x86_64-pc-linux-gnu). I would like to change the mode
for all the content (sub and subsub and subsubsub-directory... till
around 10 levels) and I expected "chmod -R" would do. How can I do that?

Jean-Yves

Ed Morton

unread,
13 Apr 2017, 12:27:0913/04/2017
to
find . -exec chmod u+w {} \+

If that syntax isn't quite right, man find.

Ed.

hymie!

unread,
13 Apr 2017, 12:29:4413/04/2017
to
In our last episode, the evil Dr. Lacto had captured our hero,
It works correctly for me:

$ ls -ld `find . -name z`
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/
drwxr-xr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/z/
drwxr-xr-x 2 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/z/z/
$ chmod -R g+w z
$ ls -ld `find . -name z`
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/
drwxrwxr-x 3 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/z/
drwxrwxr-x 2 hymie hymie 4,096 Apr 13 12:27 ./z/z/z/z/z/z/z/

Can you post an example where it doesn't work correctly?

--hymie! http://lactose.homelinux.net/~hymie hy...@lactose.homelinux.net

Thomas 'PointedEars' Lahn

unread,
13 Apr 2017, 13:39:3213/04/2017
to
Jean-Yves Baudais wrote:

> "chmod -R u+w *" change the file mode only for the content of the
> directory and the sub-directory in my computer (GNU bash, version
> 4.3.46(1)-release x86_64-pc-linux-gnu).

You must be doing something wrong. A possibility is that you have files
with name “-*” in that directory, whose name would be processed as if it
were options. Another, less likely possibility is that “*” expands to too
many or too long names; in general, it is not a good idea to rely on “*” –
you should at least test it with ls(1).

I do not see a shell option that would explain this behavior, except perhaps
“dotglob”.

> I would like to change the mode for all the content (sub and subsub and
> subsubsub-directory... till around 10 levels) and I expected "chmod -R"
> would do. How can I do that?

chmod -R u+w .

if it is the current directory, or

chmod -R u+w "$path"

if it is not.

Or with standard chmod(1), use find(1) as suggested.

If neither of that works, it is a permissions issue and you should get and
post error messages.

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Thomas 'PointedEars' Lahn

unread,
13 Apr 2017, 13:44:1813/04/2017
to
Ed Morton wrote:

> On 4/13/2017 11:21 AM, Jean-Yves Baudais wrote:
>> "chmod -R u+w *" change the file mode only for the content of the
>> directory and
>> the sub-directory in my computer (GNU bash, version 4.3.46(1)-release
>> x86_64-pc-linux-gnu). I would like to change the mode for all the content
>> (sub and subsub and subsubsub-directory... till around 10 levels) and I
>> expected "chmod -R" would do. How can I do that?
>
> find . -exec chmod u+w {} \+
>
> If that syntax isn't quite right, man find.

I know of no shell where “+” is a special character; it would certainly not
be POSIX-compliant. I do not think you need to quote it.

Otherwise, your command is equivalent to a proper use of (even POSIX)
chmod(1), and I can see no reason why one would not work but the other
should; see my other follow-up.

Thomas 'PointedEars' Lahn

unread,
13 Apr 2017, 13:47:3913/04/2017
to
hymie! wrote:
^^^^^^
Your real name belongs there.

> $ ls -ld `find . -name z`

Please don’t.

find . -type d -name z -exec ls -l '{}' +

> --hymie!

That is not a proper Usenet signature, therefore this is…

> [spam]

See below for how it is done.

Kaz Kylheku

unread,
13 Apr 2017, 17:55:0613/04/2017
to
On 2017-04-13, Jean-Yves Baudais <jean-yve...@insa-rennes.fr> wrote:
> Hello,
>
> "chmod -R u+w *" change the file mode only for the content of the
> directory

This this only changes modes for the items in the current directory
which match the expression *. If any of the items are directories, then
it recurses into those.

The * expression doesn't match directory entries which begin with a
period.

Thus the command will not change the permissions of something
called .foo, and won't recurse into it either, if it is a directory.

This is because the chmod command will not even receive such an
item as an argument. The shell expands the * expression into an
argument list of matching directory entries. This happens before
chmod is invoked. The program will only operate on the items named by
its command line arguments, and with -R, will recurse into those that
are directories.

If you mean "this directory and all its children", then just say so:

chmod -R u+w .

The name . (dot) refers to the current directory, because every
directory has an entry by that name which points to itself.

> and the sub-directory in my computer (GNU bash, version
> 4.3.46(1)-release x86_64-pc-linux-gnu). I would like to change the mode
> for all the content (sub and subsub and subsubsub-directory... till
> around 10 levels) and I expected "chmod -R" would do. How can I do that?

Why would you expect chmod -R to only go until around 10 levels?

"Around 10 levels" logically clashes with your requirement to
process "all the content". If there are 11 levels, and we only descent
to 10 levels, we are not changing the permissions of "all the content",
are we.

If around 10 levels is all the depth you actually have, then stating
this as a requirement is confusing and needless; it adds nothing
to "all the content".

Thomas 'PointedEars' Lahn

unread,
13 Apr 2017, 19:40:3213/04/2017
to
Kaz Kylheku wrote:

> On 2017-04-13, Jean-Yves Baudais <jean-yve...@insa-rennes.fr> wrote:

Attribution *line*, not attribution novel.

>> "chmod -R u+w *" change the file mode only for the content of the
>> directory
>
> […]
> The * expression doesn't match directory entries which begin with a
> period.

It does in Bash 4.4 after

shopt -s dotglob

Jean-Yves Baudais

unread,
14 Apr 2017, 03:15:4114/04/2017
to
Hello,

Thank you for all your replies. chmod works fine (of course!), in
contrast to myself! I made a false understanding of my problem. I wanted
to copy (cp -a) one home directory to another one (. instead of * is the
good way). And this cp failed because of access not allowed for some
files. So I changed the file mode in the source (maybe I verified the
file mode in the destination not in the source) but I should have done
it in the destination too, of course! Thank you again and sorry for my
stupid mistake...

Jean-Yves

Kaz Kylheku

unread,
14 Apr 2017, 10:32:3114/04/2017
to
Unless you changed all those permissions back to the original ones
after the copy, you have made another even stupider mistake.

One user doesn't have permissions to certain objects in another user's
directory *for very good security reasons*.

You should become root to copy home directory material between different
users. Something like:

$ su -
password:
# cp -p ~a/. ~b/.
# chown -R b:<group> ~/b # substitute correct group for <group>

Jean-Yves Baudais

unread,
14 Apr 2017, 11:04:1114/04/2017
to
Hello,

Le 14/04/2017 à 16:32, Kaz Kylheku a écrit :
> On 2017-04-14, Jean-Yves Baudais <jean-yve...@insa-rennes.fr> wrote:
> Unless you changed all those permissions back to the original ones
> after the copy, you have made another even stupider mistake.


Oh thank you! but don't know that because of LDAP problem I have to home
with the same user ID. So it's not a stupider mistake but you have made
too many assumptions on my stupidity :-)

Jean-Yves

Jean-Yves Baudais

unread,
14 Apr 2017, 11:05:0114/04/2017
to
Le 14/04/2017 à 17:04, Jean-Yves Baudais a écrit :
> Oh thank you! but don't know that because of LDAP problem I have to


Stupid: two, of course!

Jean-Yves
0 new messages