Mailinglist Archive: opensuse (3441 mails)

< Previous Next >
Re: [opensuse] Correct Way to Recursively Change Permissions
  • From: "Boyd Stephen Smith Jr." <bss@xxxxxxxxxxxxxxxxx>
  • Date: Tue, 13 Jan 2009 20:48:14 -0600
  • Message-id: <200901132048.18733.bss@xxxxxxxxxxxxxxxxx>
On Tuesday 2009 January 13 19:21:53 Henare Degan wrote:
I want to change permissions on a large directory structure to only RW
for the owner of all the files. If I:

chmod -R 600 /path/of/directory

it won't work because it removes the 'x' bit from the directory, which
prevents traversal. The only solution I've come up with is to:

chmod -R 700 /path/to/directory

and then:

chmod 600 `find /path/to/directory -type f`

Which seems like a round-about way to achieve this (and needs some
hackery it you have messy file names, like ones with '-' in the path),
what's the "correct" way?

chmod u+rwX,go-rwx -R /path/to/directory
*almost* does what I think you want. However, it doesn't remove the
executable bits from files that already have them. It does remove group and
other permissions from the directories (which are, from one perspective,
files as well).

Cristian Rodriguez had probably most efficient way to chmod only files,
although I prefer:
find /path/to/directory -type f -print0 | xargs -r0 -- chmod 600 --
which only spawns one more process than Cristian's and works with non-GNU find
(it still requires xargs/chmod that knows how to handle '--').
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@xxxxxxxxxxxxxxxxx ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' \_/
< Previous Next >