Discussion:
mass-changing permissions of files, recursively
Robin Paulson
2011-01-15 05:20:57 UTC
Permalink
i have a laptop, and a server which backs up the laptop. i know not
how, but the permissions on the two are out of sync. i would like to
log on to the server and change all the permissions, and do the same
on the laptop. this will require chown. can someone explain how to
recursively change the permissions of the files only, i.e. not the
folders? i want to make the files non-executable, but obviously the
folders need to be executable, so i can open them

the files need to be read and write by the owner, read by the rest of
the group, and nothing for everyone else

i could change the permissions on the laptop and then sync all the files but:
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated
2. this will take forever - there are 25,000 files, and my connection
is rather poor
3. it seems rather inelegant, most of the data hasn't changed
4. i'd like to learn the flags for chown, but reading the man page,
it's a bit over my head
--
robin

http://tangleball.org.nz/ - Auckland's Creative Space
http://bumblepuppy.org/blog/

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Matthew Poole
2011-01-15 05:23:17 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Robin Paulson
i have a laptop, and a server which backs up the laptop. i know not
how, but the permissions on the two are out of sync. i would like to
log on to the server and change all the permissions, and do the same
on the laptop. this will require chown. can someone explain how to
recursively change the permissions of the files only, i.e. not the
folders? i want to make the files non-executable, but obviously the
folders need to be executable, so i can open them
the files need to be read and write by the owner, read by the rest of
the group, and nothing for everyone else
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated
2. this will take forever - there are 25,000 files, and my connection
is rather poor
3. it seems rather inelegant, most of the data hasn't changed
4. i'd like to learn the flags for chown, but reading the man page,
it's a bit over my head
find <root dir> -type f -exec chown 640 {} \;

- --
Matthew Poole
"Don't use force. Get a bigger hammer."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk0xL0AACgkQTdEtTmUCdpzZGACgkYV5pewS/5/dUMCy4liRZ2kK
9NYAn1DPElQymnlY+lDCkOEvAHDooHx6
=wC2+
-----END PGP SIGNATURE-----

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Robin Paulson
2011-01-15 05:36:56 UTC
Permalink
Post by Matthew Poole
find <root dir> -type f -exec chown 640 {} \;
cool, cheers
--
robin

http://tangleball.org.nz/ - Auckland's Creative Space
http://bumblepuppy.org/blog/

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Atom Smasher
2011-01-15 11:38:19 UTC
Permalink
Post by Matthew Poole
Post by Robin Paulson
2. this will take forever - there are 25,000 files, and my connection
is rather poor
find <root dir> -type f -exec chown 640 {} \;
=================

with tens of thousands of files, it might be noticeably quicker to do this
instead...
find <<dir>> -type f -exec chmod <<perms>> {} +

using "+" instead of "\;" results in faster execution for this use of
find/chmod by saving thousands of forks.

a bit about its history -
http://www.in-ulm.de/~mascheck/various/find/#xargs

from ubuntu's [find] man page:
-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. The command line is built
in much the same way that xargs builds its command lines. Only one
instance of `{}' is allowed within the command. The command is executed in
the starting directory.
--
...atom

________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------

"People like crowds. The bigger the crowd, the more people
show up. Small crowd, hardly anybody shows up."
-- Gallagher


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Atom Smasher
2011-01-15 11:59:28 UTC
Permalink
of course with zsh, you can also do this -
zargs -- /<<dir>>/**/*(.) -- chmod <<perms>>

;)

man zshcontrib for more info.

"This [zargs] function works like GNU xargs, except that instead of
reading lines of arguments from the standard input, it takes them from the
command line. This is useful because zsh, especially with recursive glob
operators, often can construct a command line for a shell function that is
longer than can be accepted by an external command."
--
...atom

________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------

"I used to be disgusted; now I try to be amused."
-- Elvis Costello


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Simon Lyall
2011-01-15 05:45:22 UTC
Permalink
1. find . -type f -exec chmod 640 {} \;

2. The shift key is just above the control key on the bottom right of your
keyboard. using this you can make capital letters in your emails.
Post by Robin Paulson
i have a laptop, and a server which backs up the laptop. i know not
how, but the permissions on the two are out of sync. i would like to
log on to the server and change all the permissions, and do the same
on the laptop. this will require chown. can someone explain how to
recursively change the permissions of the files only, i.e. not the
folders? i want to make the files non-executable, but obviously the
folders need to be executable, so i can open them
the files need to be read and write by the owner, read by the rest of
the group, and nothing for everyone else
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated
2. this will take forever - there are 25,000 files, and my connection
is rather poor
3. it seems rather inelegant, most of the data hasn't changed
4. i'd like to learn the flags for chown, but reading the man page,
it's a bit over my head
--
robin
http://tangleball.org.nz/ - Auckland's Creative Space
http://bumblepuppy.org/blog/
_______________________________________________
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
--
Simon Lyall | Very Busy | Web: http://www.darkmere.gen.nz/
"To stay awake all night adds a day to your life" - Stilgar | eMT.


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Steve Holdoway
2011-01-15 05:52:43 UTC
Permalink
Post by Simon Lyall
1. find . -type f -exec chmod 640 {} \;
extremely inefficient as it calls chmod for each file. xargs will batch
them up, and can be used along with the -print0 find option to handle
embedded spaces in the file name.
Post by Simon Lyall
2. The shift key is just above the control key on the bottom right of your
keyboard. using this you can make capital letters in your emails.
I've got a \ there...

Shall we start with top posting? Chill (:

Steve
--
Steve Holdoway BSc(Hons) MNZCS <***@greengecko.co.nz>
http://www.greengecko.co.nz
MSN: ***@greengecko.co.nz
Skype: sholdowa
Justin Cook
2011-01-15 06:17:32 UTC
Permalink
Post by Steve Holdoway
Post by Simon Lyall
1. find . -type f -exec chmod 640 {} \;
extremely inefficient as it calls chmod for each file. xargs will batch
them up, and can be used along with the -print0 find option to handle
embedded spaces in the file name.
Post by Simon Lyall
2. The shift key is just above the control key on the bottom right of
your
Post by Simon Lyall
keyboard. using this you can make capital letters in your emails.
I've got a \ there...
Steve
I missed you, massive nzlug-fight.
_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Mark Foster
2011-01-15 06:49:02 UTC
Permalink
Post by Steve Holdoway
Post by Simon Lyall
1. find . -type f -exec chmod 640 {} \;
extremely inefficient as it calls chmod for each file. xargs will batch
them up, and can be used along with the -print0 find option to handle
embedded spaces in the file name.
Post by Simon Lyall
2. The shift key is just above the control key on the bottom right of your
keyboard. using this you can make capital letters in your emails.
I've got a \ there...
The AUP actually allows for either style, so long as you are consistent.

Whilst I agree that use of capital letters in correct fashion is
preferred, the comment itself could've probably been ommitted or moved
offlist, however.

Mark.


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Steve Holdoway
2011-01-15 05:47:54 UTC
Permalink
Post by Robin Paulson
i have a laptop, and a server which backs up the laptop. i know not
how, but the permissions on the two are out of sync. i would like to
log on to the server and change all the permissions, and do the same
on the laptop. this will require chown. can someone explain how to
recursively change the permissions of the files only, i.e. not the
folders? i want to make the files non-executable, but obviously the
folders need to be executable, so i can open them
the files need to be read and write by the owner, read by the rest of
the group, and nothing for everyone else
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated
2. this will take forever - there are 25,000 files, and my connection
is rather poor
3. it seems rather inelegant, most of the data hasn't changed
4. i'd like to learn the flags for chown, but reading the man page,
it's a bit over my head
Best way is...

find . -type f -print0 | xargs -0 chown u+rw

will handle files with embedded spaces in the name, and will add to,
rather than change ( as in using the numeric 644 ) permissions.

hth,

Steve
--
Steve Holdoway BSc(Hons) MNZCS <***@greengecko.co.nz>
http://www.greengecko.co.nz
MSN: ***@greengecko.co.nz
Skype: sholdowa
Bruce Clement
2011-01-15 06:45:56 UTC
Permalink
Post by Robin Paulson
i have a laptop, and a server which backs up the laptop. i know not
how, but the permissions on the two are out of sync. i would like to
log on to the server and change all the permissions, and do the same
on the laptop. this will require chown. can someone explain how to
recursively change the permissions of the files only, i.e. not the
folders? i want to make the files non-executable, but obviously the
folders need to be executable, so i can open them
the files need to be read and write by the owner, read by the rest of
the group, and nothing for everyone else
No need for find, just use the following piece of line noise:

chmod -R a-wrx,u+rwX,g+rX *

which translates into:
-R Recursively. Can also be written --recursive
a-wrx turn read, write & execute off for all
u+rwX turn read, write and directory execute back on for the file owner
g+rX turn read and directory execute back on for group members
* applies to all files and directories.
Post by Robin Paulson
4. i'd like to learn the flags for chown, but reading the man page,
it's a bit over my head
I think it's chmod you want, not chown. chown changes the user or group that
owns the file, not access to it.

HTH

Bruce
--
Bruce Clement

Home: http://www.clement.co.nz/
Twitter: http://twitter.com/Bruce_Clement
Google Buzz: http://www.google.com/profiles/aotearoanz

"Before attempting to create something new, it is vital to have a good
appreciation of everything that already exists in this field." Mikhail
Kalashnikov
_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Jim Cheetham
2011-01-15 20:43:20 UTC
Permalink
Post by Robin Paulson
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated
Read the Unison documentation, and tell it which source to prefer.
Combine with auto and batch mode to get it all done without prompting.
http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#prefs

Something like this will work :-
$ unison -auto -batch -prefer laptop laptop server

Of course you should test the action of '-prefer' by omitting the auto
and batch preferences, and possibly using it on a test set of files
that you have manually modified at both ends, and see if it fixes
them.

Manually changing permissions at the far end will not guarantee that
permissions match anyway, unless you have checked the modes for all
25,000 files already.

-jim

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Robin Paulson
2011-01-18 02:34:29 UTC
Permalink
Post by Jim Cheetham
Read the Unison documentation, and tell it which source to prefer.
Combine with auto and batch mode to get it all done without prompting.
http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#prefs
Something like this will work :-
$ unison -auto -batch -prefer laptop laptop server
Of course you should test the action of '-prefer' by omitting the auto
and batch preferences, and possibly using it on a test set of files
that you have manually modified at both ends, and see if it fixes
them.
ok, i'm lost here - i don't understand why this helps. i don't want to
re-transmit the entire set of files, if the only difference is the
permissions, cos there are loads of them

either i'm being slow (i think i am), or the above appears to do exactly that
Post by Jim Cheetham
Manually changing permissions at the far end will not guarantee that
permissions match anyway, unless you have checked the modes for all
25,000 files already.
sorry, i don't understand this last bit either. and what are modes, in
this context?
--
robin

http://tangleball.org.nz/ - Auckland's Creative Space
http://bumblepuppy.org/blog/

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Jim Cheetham
2011-01-18 04:20:05 UTC
Permalink
Post by Robin Paulson
Post by Jim Cheetham
Something like this will work :-
$ unison -auto -batch -prefer laptop laptop server
ok, i'm lost here - i don't understand why this helps. i don't want to
re-transmit the entire set of files, if the only difference is the
permissions, cos there are loads of them
You are asking Unison to compare laptop with server; it will only copy
files if there are any changes. If files are the same at both end, no
files will be copied. But it still has to compare the whole lot. (I
also misread your original email, you need "-prefer server" as the
server is the one that has the original files) (oh, and "server" and
"laptop" both need to be expressed as suitable directory names or URIs
like ssh://remotehostname/directory)

I had assumed that you were already using Unison to make your backups
(which isn't necessarily good practice -- rsync is more likely to be
what you need), and was therefore pointing out how to use unison in a
slightly "better" way.
Post by Robin Paulson
1. unison is confused, and wants me to individually say which file
(server or laptop) should be propagated

If you have never used Unison between these two file sets before, and
did not use the "-prefer" option, if any differences were detected it
would have to ask you what to do. In fact, I expect it was asking you
what to do about the only differences, which are hopefully just the
permissions.
Post by Robin Paulson
Post by Jim Cheetham
Manually changing permissions at the far end will not guarantee that
permissions match anyway, unless you have checked the modes for all
25,000 files already.
sorry, i don't understand this last bit either. and what are modes, in
this context?
"modes" is effectively a synonym for "permissions". The "mode" of a
file controls what access permissions are granted when a process tries
to access a file. For conversational purposes, "modes" and
"permissions" are the same thing.

What I was trying to say was that if you just go and "fix the
permissions" on your laptop copy of the files, but you didn't know for
sure what the actual permissions were on the server copy in the first
place, you would not necessarily be better off at the end of the day
-- assuming that your problem right now is that "permissions don't
match".
Post by Robin Paulson
but the permissions on the two are out of sync
Actually, your biggest problem is probably that you don't know how the
server is backing up to the laptop in the first place. If that process
is breaking things, you're wasting your time trying to fix them by
hand -- they might just break next time the backup runs.

-jim

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Jim Cheetham
2011-01-18 04:23:44 UTC
Permalink
Post by Robin Paulson
Post by Jim Cheetham
Something like this will work :-
$ unison -auto -batch -prefer laptop laptop server
ok, i'm lost here - i don't understand why this helps.
I wasn't very explicit about that, either. As well as synchronising
file contents, Unison (like rsync) will synchronise the permissions.
If the contents are already OK, Unison will just fix the permissions
to whatever the original (i.e the "-prefer"red) source was.

But from my email a few minutes ago, I only talked about Unison
because you indicated that you were already playing with it. It isn't
the best choice for getting yourself out of trouble caused by
something else ...

-jim

_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug

Loading...