How to 'find -perm' for *unset* modes?

How to 'find -perm' for *unset* modes?

Post by Brent Busb » Tue, 10 Feb 2004 23:22:52



Here's the problem:

If I simply 'chmod -R' a directory tree, every single file and directory
in that tree will have its ctime changed.  If you're keeping incremental
backups (which you should be!), you won't like that.  It will make the
entire directory tree seem "new" at the time of your next backup.  Even
files that already had modes that agree with the mode you were setting
will have their ctimes updated anyway.  To test this, do 'ls -cl' on a
file, then chmod it with the mode it already has, then 'ls -cl' it
again.  The mode and the ctime are changed even when it's not necessary.  
Your next incremental backup will save a redundant copy of this file.  
If you did that as part of a 'chmod -R' on a whole tree, you will now
eat several megabytes of tape for nothing.

The _partial_ solution:

GNU find includes options for matching modes, either exactly, or all
those specified, or any of those specified.  It can also execute
arbitrary commands with the '-exec' option if it finds a hit, which
makes it possible to do a sort of "conditional recursive chmod" as it
were using GNU find.  So why is this only a partial solution?

Because I don't see any way to match bits that are NOT set.

The only way I can do that is if I want to match a whole mode exactly.  
For example, I could say:

find ~/dir -type f -perm 0600 -exec chmod g+r {} \;

But that would depend on finding the EXACT mode 0600.  How do you do
this type of conditional chmod looking for individual cleared bits?  In
other words, I want to do something like 'find -perm +mode', which looks
for *any* of the specified bits set...but in REVERSE.  I want to look
for individual arbitrary bits that are NOT set, and do '-exec chmod'.

Any special incantations anyone might know to accomplish this?

BTW:  I don't care that it necessarily has to be a find command.  Perl,
awk, bash...whatever.  It's all very kosher.  <g>

--
+ Brent A. Busby,       "The killer application for Windows was Visual
+ CATMIND RECORDINGS     Basic. It allowed you to make your hokey, self-

+ Pekin, IL   (USA)      your enterprise...."  --Linus Torvalds

 
 
 

How to 'find -perm' for *unset* modes?

Post by Barry Margoli » Wed, 11 Feb 2004 00:14:29




Quote:> Because I don't see any way to match bits that are NOT set.

Use the "!" negation operator.

Quote:

> The only way I can do that is if I want to match a whole mode exactly.  
> For example, I could say:

> find ~/dir -type f -perm 0600 -exec chmod g+r {} \;

> But that would depend on finding the EXACT mode 0600.  How do you do
> this type of conditional chmod looking for individual cleared bits?  In
> other words, I want to do something like 'find -perm +mode', which looks
> for *any* of the specified bits set...but in REVERSE.  I want to look
> for individual arbitrary bits that are NOT set, and do '-exec chmod'.

find ~/dir -type -f ! -perm -040 -exec chmod g+r {} \;

will set the group read bit on any files that don't already have it set.

--

Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

 
 
 

How to 'find -perm' for *unset* modes?

Post by those who know me have no need of my nam » Wed, 11 Feb 2004 05:56:54


in comp.unix.shell i read:

Quote:>If I simply 'chmod -R' a directory tree, every single file and directory
>in that tree will have its ctime changed.  If you're keeping incremental
>backups (which you should be!), you won't like that.  It will make the
>entire directory tree seem "new" at the time of your next backup.  

barry's response might be just what you want, but i've got a slightly
different take on it you might want to consider ...

this is part of the problem: you know that ctime only records the change
time of the meta-data, but at the same time you talk of files and
directories being `new' -- so while you understand the difference you use
ctime anyway.

the other part is: if the mode is changed don't you want that recorded?
surely you should want it, but i suspect that your backup tools don't allow
you to backup only the meta-data (ctime > last backup) without also backing
up the data (mtime <= last backup).  it's useful to only change the mode of
those files which need changing, so using find ! -perm is quite applicable.

--
a signature

 
 
 

How to 'find -perm' for *unset* modes?

Post by Ian Zimmerma » Mon, 16 Feb 2004 06:38:52


[...]
Brent> Because I don't see any way to match bits that are NOT set.

Brent> BTW:  I don't care that it necessarily has to be a find command.  Perl,
Brent> awk, bash...whatever.  It's all very kosher.  <g>

<plug>
http://www.cpan.org/authors/id/T/TH/THEDEVIL/permafrost-20021022
</plug>

--
Nothing can be explained to a stone.
Or to a stoned person, either.

 
 
 

1. ksh: 'unset' variables in 'regexp-like' fashion?

The problem is this: a script generates (very) many
variables that have a certain pattern to them, like this:

   $ AB_0_0=1
   $ AB_0_1=2

At some point I need to 'unset' all of them:

   $ unset AB_0_0 AB_0_1

This is practical only for a few of them. Is there a way
to unset all of them in some simple fashion, like

   $ unset AB*  

I know the above (which is meant to be 'regexp-like')
doesn't work, but this is the idea I am after.

If the variables were all exported, one could think of
something like (not pretty):

   $ env | grep '^AB' | while read var
                        do unset ${var%%=*}
                        done

but my variables are not exported (so 'env' doesn't output
them).

Any idea?

---Zdenek

--
=========================================================

VNET: 557-4844                      Silicon Graphics SA
Tel : +41-22-710.4844       18, Ave. Louis Casai, 1209 Geneva
Fax : +41-22-710.4860                   Switzerland

2. X86 on NexGen?

3. suppressing 'no perm' msg in find

4. WTB: VA Linux 9205SE disk array

5. 'Find' 'Updatedb' or find database replacement for Solaris 2.X?

6. X11 Forwarding except ssh

7. How to unset 'tab' on xterm ... ??

8. Kernel Panic with Syjet

9. Can I chg deflt perms on 'enable'?

10. Why did 'nobody' do a 'find'

11. KDE Failes to find '__ti6QFrame' in 'ld-elf.so.1' on FreeBSD

12. Sting search w/o 'find' or 'du'

13. Who is 'nobody' and why 'find'