Re: /usr/bin/find - binary operands howto

2012-06-05 Thread grarpamp
A single find already had the needed selection and execution ops.
So I was trying it first, before writing an external parser, etc.

It's still not clear to me how find is compiling the arguments
internally, but using -vv on the utils helped a lot. After adding
-false after all the -exec's, it now works as desired up against
my array of inodes. I also worked in a pre-change, select, ls.

The arbitrary format of gfind is interesting. It can maybe be
approximated in find with -exec ls someargs {} \+.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: /usr/bin/find - binary operands howto

2012-06-04 Thread Karl Vogel
 On Sun, 3 Jun 2012 19:10:00 -0400, 
 grarpamp grarp...@gmail.com said:

G Given a fs with millions of inodes, multiple find runs is expensive.  As
G is performing the ch* on more than the minimum required inodes, which
G also needlessly updates the inode ctime. So I want one find, doing the
G ch* only if necessary.  So how should I write this? Do I want to use
G -true/-false somehow?

   It might be more efficient to keep find output in either a flat file or DB,
   so you can avoid multiple walks over the filetree.  You'll need GNU find:

   #!/bin/sh
   export PATH=/usr/local/bin:/bin:/usr/bin
   test $1 || set .

   echo '#filetype|inode|links|uname|gname|mode|size|mtime|pathname'
   gfind $@ -printf '%y|%i|%n|%u|%g|%m|%s|%T@|%p\n'
   exit 0

   Sample output:

   root# chown 1234 stuff
   root# chgrp 5678 stuff

   me% ls -l
   drwxr-sr-x 3 kev   local512 04-Jun-2012 21:01:41 .
   drwxr-xr-x 2 kev   local512 04-Jun-2012 21:38:47 mail
   -rw-r--r-x 1 kev   local  47072 04-Jun-2012 19:34:26 mail/junk*
   -rw-r--r-- 1 1234   5678 85 19-May-2012 23:28:30 stuff
   -rw-r--r-- 1 kev   local   8104 04-Jun-2012 19:43:44 testing

   me% [run script]
   #filetype|inode|links|uname|gname|mode|size|mtime|pathname
   d|873603|3|kev|local|2755|512|1338858101|.
   d|1188634|2|kev|local|2755|512|1338860327|./mail
   f|1188649|1|kev|local|645|47072|1338852866|./mail/junk
   f|955452|1|1234|5678|644|85|1337484510|./stuff
   f|873708|1|kev|local|644|8104|1338853424|./testing

   Run this first, then look for the conditions you want using awk or perl.
   Advantages:

   * Doesn't change ctime, no additional filetree-walking.

   * You can use this to create your locate DB, if you want to avoid a
 second pass through the filesystem.

   * Gives you a point-in-time picture of ownership, mode, etc. in case
 you need to back out your changes.

-- 
Karl Vogel  I don't speak for the USAF or my company

When I read about the evils of drinking, I gave up reading.  --Henny Youngman
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


/usr/bin/find - binary operands howto

2012-06-03 Thread grarpamp
Given a fs with millions of inodes, multiple find runs is expensive.
As is performing the ch* on more than the minimum required inodes,
which also needlessly updates the inode ctime. So I want one find,
doing the ch* only if necessary.

I came up with this. But any true line short circuits the rest of
the -o's, which isn't desired. Using -a results similarly.

The man page says -exec returns true if util is true. ch* is usually
true unless the operation isn't permitted (file flags, read-only,
etc) or the node vanishes in a race.

The test[s] would keep -exec[s] from being always executed.

Then there is the problem of the full permutation of the initial
state of the owner and mode, say: 00, 01, 10, 11.

So how should I write this? Do I want to use -true/-false somehow?

# touch 1 ; chown 1:1 1 ; chmod 0666 1 ; ls -l 1

# find 1 \( \
\( \! \( -uid 0 -gid 0 \) -exec chown 0:0   {} \+ \) \
 -o \
\(-perm +0222 -exec chmod ugo-w {} \+ \) \
 -o \
...
 -o \
...
\)

# ls -l 1
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org