From owner-freebsd-questions@FreeBSD.ORG Sun Mar 13 10:15:17 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 B85FA16A4CE for ; Sun, 13 Mar 2005 10:15:17 +0000 (GMT) Received: from hosea.tallye.com (joel.tallye.com [216.99.199.78]) by mx1.FreeBSD.org (Postfix) with ESMTP id 278B543D58 for ; Sun, 13 Mar 2005 10:15:17 +0000 (GMT) (envelope-from lorenl@alzatex.com) Received: from hosea.tallye.com (hosea.tallye.com [127.0.0.1]) by hosea.tallye.com (8.12.8/8.12.10) with ESMTP id j2DAF1UQ019484 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Mar 2005 02:15:02 -0800 Received: (from sttng359@localhost) by hosea.tallye.com (8.12.8/8.12.10/Submit) id j2DAF0pc019482; Sun, 13 Mar 2005 02:15:00 -0800 X-Authentication-Warning: hosea.tallye.com: sttng359 set sender to lorenl@alzatex.com using -f Date: Sun, 13 Mar 2005 02:15:00 -0800 From: "Loren M. Lang" To: Giorgos Keramidas Message-ID: <20050313101500.GE18080@alzatex.com> References: <20050312115359.C14EF4BE6D@ws1-1.us4.outblaze.com> <42330B26.2040508@haystacks.org> <20050312195302.GA77874@gothmog.gr> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VUDLurXRWRKrGuMn" Content-Disposition: inline In-Reply-To: <20050312195302.GA77874@gothmog.gr> User-Agent: Mutt/1.4.1i X-GPG-Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc X-GPG-Fingerprint: B3B9 D669 69C9 09EC 1BCD 835A FAF3 7A46 E4A3 280C cc: Eric McCoy cc: freebsd-questions@freebsd.org cc: Fafa Diliha Romanova 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: Sun, 13 Mar 2005 10:15:17 -0000 --VUDLurXRWRKrGuMn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 12, 2005 at 09:53:02PM +0200, Giorgos Keramidas wrote: > 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 {} \; >=20 > Uhm, why? Even if that were possible, isn't clarity more important that > stuffing as many actions as possible in one line? >=20 > What you list above is similar to the way I use for changing the > permissions of files/dirs and it works all the time. >=20 > 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: Summing it up into one command does not neccessarily mean it's longer or more complicated. I use the following command all the time to fix permissions similar to what he seems to be doing. Though it's not technically equivalent, it's probably all he needs. chmod -R u=3DrwX,go=3DrX . My umask of 022 simplifies the command to the following: chmod -R =3DrwX . >=20 > find . | while read line; do > mode=3D'' > [ -d "${line}" ] && mode=3D0755 > [ -f "${line}" ] && mode=3D0644 >=20 > [ -n "${mode}" ] && echo "chmod ${mode} \"${line}\"" > done | sh >=20 > But this is getting quickly very difficult to remember easily and repeat > consistently every time you want to do something similar :) >=20 > >> 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 >=20 > This is an excellent way to do this, IMHO. >=20 > > If you were feeling crazy and use sh: > > > > find . | while read path; do \ > > if [ -d "$path" ]; then chmod 755; > > else chmod 644; fi; \ > > done >=20 > I guess you meant to write: >=20 > find . | while read path; do \ > if [ -d "$path" ]; then chmod 755 "${path}"; > else chmod 644 "${path}"; fi; \ > done >=20 > Otherwise, many chmod failures are the only result. >=20 > 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). >=20 > - Giorgos >=20 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" --=20 I sense much NT in you. NT leads to Bluescreen. Bluescreen leads to downtime. Downtime leads to suffering. NT is the path to the darkside. Powerful Unix is. Public Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc Fingerprint: CEE1 AAE2 F66C 59B5 34CA C415 6D35 E847 0118 A3D2 =20 --VUDLurXRWRKrGuMn Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFCNBKkbTXoRwEYo9IRAgIBAJ9k9Q6M632ClfESlmQKoD2nWM8ApgCeJY0f UUVl6DqB3LWY/Idsijhg41U= =FKF7 -----END PGP SIGNATURE----- --VUDLurXRWRKrGuMn--