From owner-freebsd-questions Wed Nov 10 8:49:48 1999 Delivered-To: freebsd-questions@freebsd.org Received: from laurasia.com.au (lauras.lnk.telstra.net [139.130.93.142]) by hub.freebsd.org (Postfix) with ESMTP id 6DF43153A4 for ; Wed, 10 Nov 1999 08:49:34 -0800 (PST) (envelope-from mike@laurasia.com.au) Received: (from mike@localhost) by laurasia.com.au (8.9.1a/8.9.1) id BAA05709 for freebsd-questions@freebsd.org; Thu, 11 Nov 1999 01:04:29 +0800 (WST) From: Michael Kennett Message-Id: <199911101704.BAA05709@laurasia.com.au> Subject: Testing file permissions To: freebsd-questions@freebsd.org Date: Thu, 11 Nov 1999 01:04:29 +0800 (WST) X-Mailer: ELM [version 2.4ME+ PL32 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hello All, How do I test the permissions of a file in a script? I'm making some changes to the daily admin scripts, and I'd like to test the permissions and ownership of a couple of files and directories. The only way I can do it is to use the `ls -l' command and to process the text output. e.g. To test that the /bin/ls command is world executable (trivial example): if [ -f /bin/ls ] && ( ls -l /bin/ls | cut -b 4 | grep x > /dev/null ) then echo "World Executable" fi This seems *rather* crude! An alternative approach (just thought of it!) would be to use the 'find' command: if find /bin -name ls -perm -400 | grep ls > /dev/null then echo "World Executable" fi But this is equally crude -- indeed, I feel like I'm smashing the problem with the biggest sledgehammer that I can find! Is there another way of doing this test of file permissions? Similarly, is there a quick test for checking the ownership of a file? Regards, Mike Kennett (mike@laurasia.com.au) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message