From owner-freebsd-questions Wed Nov 10 9: 5:37 1999 Delivered-To: freebsd-questions@freebsd.org Received: from mail.telestream.com (mail.telestream.com [205.238.4.5]) by hub.freebsd.org (Postfix) with ESMTP id 16AD514DED for ; Wed, 10 Nov 1999 09:05:28 -0800 (PST) (envelope-from keith@mail.telestream.com) Received: from localhost (keith@localhost) by mail.telestream.com (8.9.3/8.9.3) with ESMTP id KAA13237; Wed, 10 Nov 1999 10:08:49 -0800 Date: Wed, 10 Nov 1999 10:08:49 -0800 (PST) From: To: Michael Kennett Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Testing file permissions In-Reply-To: <199911101704.BAA05709@laurasia.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG You can just test the file attributes... -d file exists and is a directory -e file exists -f file exists and is a regular file -r you have read permissions on the file -s file exists and is not empy -w You have write permisions on the file -x You have execute permissions on the file -O You own the file -G Files group IS matches yours On Thu, 11 Nov 1999, Michael Kennett wrote: > 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 > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message