From owner-freebsd-questions@FreeBSD.ORG Sat Mar 12 19:53:13 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 37B0716A4CE for ; Sat, 12 Mar 2005 19:53:13 +0000 (GMT) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 80BA843D1F for ; Sat, 12 Mar 2005 19:53:11 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a154.otenet.gr [212.205.215.154]) j2CJqlDf008670; Sat, 12 Mar 2005 21:52:48 +0200 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.3/8.13.3) with ESMTP id j2CJr34V078119; Sat, 12 Mar 2005 21:53:03 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.13.3/8.13.3/Submit) id j2CJr3rl078118; Sat, 12 Mar 2005 21:53:03 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Sat, 12 Mar 2005 21:53:02 +0200 From: Giorgos Keramidas To: Eric McCoy , Fafa Diliha Romanova Message-ID: <20050312195302.GA77874@gothmog.gr> References: <20050312115359.C14EF4BE6D@ws1-1.us4.outblaze.com> <42330B26.2040508@haystacks.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42330B26.2040508@haystacks.org> cc: freebsd-questions@freebsd.org Subject: Re: chmod equivalent to find commands X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Mar 2005 19:53:13 -0000 On 2005-03-12 10:30, Eric McCoy wrote: >Fafa Diliha Romanova wrote: >> hello. >> >> i know there's an equivalent to these two find commands that >> can be summed up in one chmod command: >> >> find . -type d -exec chmod 755 {} \; >> find . -type f -exec chmod 644 {} \; Uhm, why? Even if that were possible, isn't clarity more important that stuffing as many actions as possible in one line? What you list above is similar to the way I use for changing the permissions of files/dirs and it works all the time. There's no reason to try to write one, long, complicated command just for the sake of making it one command instead of two. Otherwise, you may as well do more complex stuff like: find . | while read line; do mode='' [ -d "${line}" ] && mode=0755 [ -f "${line}" ] && mode=0644 [ -n "${mode}" ] && echo "chmod ${mode} \"${line}\"" done | sh But this is getting quickly very difficult to remember easily and repeat consistently every time you want to do something similar :) >> what would be the best solution here? > > I would do it the same way you do, but with xargs instead: > > find . -type X -print0 | xargs -0 chmod XXX This is an excellent way to do this, IMHO. > If you were feeling crazy and use sh: > > find . | while read path; do \ > if [ -d "$path" ]; then chmod 755; > else chmod 644; fi; \ > done I guess you meant to write: find . | while read path; do \ if [ -d "$path" ]; then chmod 755 "${path}"; else chmod 644 "${path}"; fi; \ done Otherwise, many chmod failures are the only result. But this has a minor buglet. It will change everything that is not a directory to mode 0644. This mode is ok for files, but it may not be ok (or it may even fail) for other stuff (symbolic links, for instance). - Giorgos