From owner-freebsd-questions@FreeBSD.ORG Sun Jun 3 23:10:02 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AF5C8106566B for ; Sun, 3 Jun 2012 23:10:02 +0000 (UTC) (envelope-from grarpamp@gmail.com) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 3DAB18FC15 for ; Sun, 3 Jun 2012 23:10:02 +0000 (UTC) Received: by werg1 with SMTP id g1so3154944wer.13 for ; Sun, 03 Jun 2012 16:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=wGaHCeE6LFL6mzSK8m/lxstfb0qF8R2vL6w0MzF9Zxo=; b=wsvoHE+NtfB2j+6Vq/Y6OY7V3ayZjujS55EUP1gvqsesMQZj1e0qUORmxMnk1xS8Pf W8gbPN+SjaJ6KmoYyS5q5XlXijbWM187oKnhJFi6kezkGafjl8dD/EZf+TTBYNSJCGRK bu82PUT2mmFC9qfVqpEwTdupOEUuWfRfyVGsShJNkDTpyyruKf3C/3A5PdoPmoo5UiIQ fie0bSDw01Z19mBA4yCONUO06JQkucxVlHrh2m8aqflr6SMNqyJqj8Nzwga9uGoBezS+ H6KiTThP4onXV/LHZB6ZhhgJPk8IiJUBjtGfUMw/p3I3IqHccX94hi6yApIuT+IeHIKp HXHQ== MIME-Version: 1.0 Received: by 10.216.211.131 with SMTP id w3mr8842846weo.163.1338765000328; Sun, 03 Jun 2012 16:10:00 -0700 (PDT) Received: by 10.180.84.39 with HTTP; Sun, 3 Jun 2012 16:10:00 -0700 (PDT) Date: Sun, 3 Jun 2012 19:10:00 -0400 Message-ID: From: grarpamp To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 Subject: /usr/bin/find - binary operands howto X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jun 2012 23:10:02 -0000 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