...making Linux just a little more fun!
Mike Orr [sluggoster at gmail.com]
Is there a version of chmod/chown that recursively changes files only if they're different from the specification? The stock version changes them unconditionally, which updates their 'ctime' and thus makes 'rsync' transfer the inode properties even if there's no real change. I could write a Python version, but I was hoping there might be a C version somewhere that would be more efficient with millions of filenames.
-- Mike Orr <sluggoster@gmail.com>
Anderson Silva [afsilva at gmail.com]
On Thu, Oct 15, 2009 at 2:18 PM, Mike Orr <sluggoster@gmail.com> wrote:
> Is there a version of chmod/chown that recursively changes files only > if they're different from the specification? The stock version > changes them unconditionally, which updates their 'ctime' and thus > makes 'rsync' transfer the inode properties even if there's no real > change. I could write a Python version, but I was hoping there might > be a C version somewhere that would be more efficient with millions of > filenames. >
By 'specification' do you mean a RPM spec file?
rpm -V package to see what has changed rpm --setperms and --setugids
would do the trick.
AS
-- https://www.the-silvas.com
Deividson Okopnik [deivid.okop at gmail.com]
2009/10/15 Anderson Silva <afsilva@gmail.com>:
> On Thu, Oct 15, 2009 at 2:18 PM, Mike Orr <sluggoster@gmail.com> wrote: > By 'specification' do you mean a RPM spec file? >
I guess he meant from what you specify - eg, if you chmod 777 a file, and its already 777, it should skip the file, not set the permissions again.
Thomas Adam [thomas.adam22 at gmail.com]
On Thu, Oct 15, 2009 at 11:18:15AM -0700, Mike Orr wrote:
> Is there a version of chmod/chown that recursively changes files only > if they're different from the specification? The stock version > changes them unconditionally, which updates their 'ctime' and thus > makes 'rsync' transfer the inode properties even if there's no real > change. I could write a Python version, but I was hoping there might > be a C version somewhere that would be more efficient with millions of > filenames.
Yes, use find(1) to do this.
-- Thomas Adam
-- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci.
Anderson Silva [afsilva at gmail.com]
On Thu, Oct 15, 2009 at 2:59 PM, Thomas Adam <thomas.adam22@gmail.com> wrote:
> On Thu, Oct 15, 2009 at 11:18:15AM -0700, Mike Orr wrote: >> Is there a version of chmod/chown that recursively changes files only >> if they're different from the specification? The stock version >> changes them unconditionally, which updates their 'ctime' and thus >> makes 'rsync' transfer the inode properties even if there's no real >> change. I could write a Python version, but I was hoping there might >> be a C version somewhere that would be more efficient with millions of >> filenames. > > Yes, use find(1) to do this.
+1 on that...
find . -user xuser1 -exec chown -R user2 {} \;
or
find . -perm -220
etc...
-- https://www.the-silvas.com
Thomas Adam [thomas.adam22 at gmail.com]
On Thu, Oct 15, 2009 at 03:42:01PM -0400, Anderson Silva wrote:
> On Thu, Oct 15, 2009 at 2:59 PM, Thomas Adam <thomas.adam22@gmail.com> wrote: > > On Thu, Oct 15, 2009 at 11:18:15AM -0700, Mike Orr wrote: > >> Is there a version of chmod/chown that recursively changes files only > >> if they're different from the specification? ?The stock version > >> changes them unconditionally, which updates their 'ctime' and thus > >> makes 'rsync' transfer the inode properties even if there's no real > >> change. ?I could write a Python version, but I was hoping there might > >> be a C version somewhere that would be more efficient with millions of > >> filenames. > > > > Yes, use find(1) to do this. > > > +1 on that... > > find . -user xuser1 -exec chown -R user2 {} \;
No. Not like that.
> or > > find . -perm -220
... and yes, exactly like that, if only because find will call stat(2) directly to determine this, and if I am reading the source correctly for find, it won't touch the file if it's matched the permission. (It's unclear from Mike whether "-perm /200" is more applicable here or not, but it's academic at this point.)
-- Thomas Adam
-- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci.
Mike Orr [sluggoster at gmail.com]
On Thu, Oct 15, 2009 at 12:42 PM, Anderson Silva <afsilva@gmail.com> wrote:
> On Thu, Oct 15, 2009 at 2:59 PM, Thomas Adam <thomas.adam22@gmail.com> wrote: >> On Thu, Oct 15, 2009 at 11:18:15AM -0700, Mike Orr wrote: >>> Is there a version of chmod/chown that recursively changes files only >>> if they're different from the specification? The stock version >>> changes them unconditionally, which updates their 'ctime' and thus >>> makes 'rsync' transfer the inode properties even if there's no real >>> change. I could write a Python version, but I was hoping there might >>> be a C version somewhere that would be more efficient with millions of >>> filenames. >> >> Yes, use find(1) to do this. > > +1 on that... > > find . -user xuser1 -exec chown -R user2 {} \; > > or > > find . -perm -220 > > etc...
Thanks. I'll need to make it a bit more elaborate than that though because I want to avoid '-R' completely. What I really want to do is find files that don't have a 'user1:group1:mode1' combination and change those. I guess I can do several finds over the same tree, or make a Python program to set up the finds (which might be more flexible anyway).
By the way, hi Anderson from long ago when I used to edit your articles. Thanks for your help.
-- Mike Orr <sluggoster@gmail.com>
Thomas Adam [thomas.adam22 at gmail.com]
On Thu, Oct 15, 2009 at 12:52:09PM -0700, Mike Orr wrote:
> On Thu, Oct 15, 2009 at 12:42 PM, Anderson Silva <afsilva@gmail.com> wrote: > > > > find . -user xuser1 -exec chown -R user2 {} \; > > > > or > > > > find . -perm -220 > > > > etc... > > Thanks. I'll need to make it a bit more elaborate than that though > because I want to avoid '-R' completely. What I really want to do is > find files that don't have a 'user1:group1:mode1' combination and > change those. I guess I can do several finds over the same tree, or
find /foo -type f -not -perm -something ...
> make a Python program to set up the finds (which might be more > flexible anyway).
No need. I guarantee you that find can do it all for you.
You find some of the techniques used here applicable:
https://linuxgazette.net/111/tag/4.html
-- Thomas Adam
-- "It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci.