[opensuse] Correct Way to Recursively Change Permissions
Hi list, 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? Cheers, h -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday January 13 2009, Henare Degan wrote:
Hi list,
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?
Look into the symbolic mode changing syntax, which includes incremental notations for adding or removing permissions. E.g.: # Add execute permissions: % chmod +x ... # Remove write permissions: % chmod -g ... # Take away write permissions only from group and world (all): % chmod ga-w ... # Give owner write and read permissions: % chmod o+rw ... etc.
Cheers,
h
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday January 13 2009, Randall R Schulz wrote:
On Tuesday January 13 2009, Henare Degan wrote:
...
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?
Look into the symbolic mode changing syntax, which includes incremental notations for adding or removing permissions.
E.g.:
# Add execute permissions: % chmod +x ...
% chmod -g ...
Insufficient proofreading... That should be: # Remove write permissions: % chmod g-x
# Take away write permissions only from group and world (all): % chmod ga-w ...
# Give owner write and read permissions: % chmod o+rw ...
RRS -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
El Miércoles, 14 de Enero de 2009 Henare Degan escribió:
Hi list,
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?
find <path> -type f -print0 | xargs -0 -l1-n1 chmod -c u=rw
Cheers,
h
-- No lea este correo si no es necesario. El buen ambiente está en nuestras manos. ->>----------------------------------------------- Clist UAH a.k.a Angel ---------------------------------[www.uah.es]-<<-- Hoy no has conseguido la iluminación divina. No importa mañána será otro día... -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Henare Degan escribió:
Hi list,
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
find /path/of/directory -type f -exec chmod 600 {} + -- "We have art in order not to die of the truth" - Friedrich Nietzsche Cristian Rodríguez R. Software Developer Platform/OpenSUSE - Core Services SUSE LINUX Products GmbH Research & Development http://www.opensuse.org/
On Wed, Jan 14, 2009 at 12:42, Cristian Rodríguez
find /path/of/directory -type f -exec chmod 600 {} +
Thanks very much to everyone that responded. I always thought there was an option of chmod (or similar) that did not change the 'x' bit on directories but I guess not. I found Cristian's solution the most elegant (I even learnt a bit more about the -exec option of find, after bothering to read the man page to understand what the curly braces and plus did at the end of the command). Randall, using the symbolic mode versus numeric mode doesn't change how the command affects directories versus files (although I may have missed the point you were making in your mail ;) Thanks again everyone, h -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday January 13 2009, Henare Degan wrote:
On Wed, Jan 14, 2009 at 12:42, Cristian Rodríguez
wrote: find /path/of/directory -type f -exec chmod 600 {} +
Thanks very much to everyone that responded. I always thought there was an option of chmod (or similar) that did not change the 'x' bit on directories but I guess not.
I found Cristian's solution the most elegant (I even learnt a bit more about the -exec option of find, after bothering to read the man page to understand what the curly braces and plus did at the end of the command).
Randall, using the symbolic mode versus numeric mode doesn't change how the command affects directories versus files (although I may have missed the point you were making in your mail ;)
% chmod -R o+rw /path/of/directory If an entry has execute bits, it will keep them, if it doesn't, it won't get them. Isn't that what you want? If there are a lot of files in the hierarchy, all the solutions based on the -exec option to find will be significantly slowed because a fork / exec pair will have to happen for each file. With a recursive use of chmod a single process will do all the work, which is far more efficient.
Thanks again everyone,
h
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wed, Jan 14, 2009 at 13:29, Randall R Schulz
If an entry has execute bits, it will keep them, if it doesn't, it won't get them.
Isn't that what you want?
I think that is what I was thinking of but my problem is some of the files in the tree have the execute bit set (copied from FAT-based camera SD cards) and I want this removed. Also note that the command Cristian only creates one fork to exec (AFAICT), i.e. `chown 600 /a/really /long/list /of/full /paths/to /individual/files` because of the '{} +' in the -exec statement (this is the new thing I learnt I was referring to earlier). From the man page for find: "-exec command {} + This variant of the -exec action runs the specified command on the selected files, but the command line is built by *appending each selected file name at the end*; the total number of invocations of the command will be much less than the number of matched files." [Emphasis mine] Cheers, h -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday January 13 2009, Henare Degan wrote:
On Wed, Jan 14, 2009 at 13:29, Randall R Schulz wrote:
If an entry has execute bits, it will keep them, if it doesn't, it won't get them.
Isn't that what you want?
I think that is what I was thinking of but my problem is some of the files in the tree have the execute bit set (copied from FAT-based camera SD cards) and I want this removed.
Be careful. You may find that the files no longer behave the way you want them to under Windows.
Also note that the command Cristian only creates one fork ... ... From the man page for find:
"-exec command {} + This variant of the -exec action runs the specified command on the selected files, but the command line is built by *appending each selected file name at the end*; the total number of invocations of the command will be much less than the number of matched files." [Emphasis mine]
OK. That's cool, and a new one to me.
Cheers,
h
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday, 2009-01-14 at 12:21 +1100, 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: ...
Another method: use midnight commander (mc). Tell it to find all files in the directory tree, select "panelize", mark them all (*), then in the file menu select chmod. I don't know if it is better or worse, but it is easier to remember ;-) - -- Cheers, Carlos E. R. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkltRPwACgkQtTMYHG2NR9X7vgCgir4QwS8tlKKVloOhF2RO6+EN HtgAoJen+mJ96uLx5uf92OYWf280cNlI =g9j4 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/ \_/
Hello, On Wed, 14 Jan 2009, 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?
The command chmod -R u=rwX,go= /path/to/directory should do exactly what you want. HTH, -dnh -- In /etc is what you think. In /proc is, what the OS thinks. -- Thomas Blum in doc -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, Jan 15, 2009 at 11:52, David Haller
The command
chmod -R u=rwX,go= /path/to/directory
should do exactly what you want.
Thanks David - that's it! The capital 'X' does the trick (I knew there was some way). Thanks again to everyone, I learnt a few things in this thread (including the fact I should more carefully read man pages: "...execute/search only if the file is a directory or already has execute permission for some user (X)...") Cheers, h -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Angel Alvarez
-
Boyd Stephen Smith Jr.
-
Carlos E. R.
-
Cristian Rodríguez
-
David Haller
-
Henare Degan
-
Randall R Schulz