Date: Wed, 10 Nov 1999 10:08:49 -0800 (PST) From: <keith@mail.telestream.com> To: Michael Kennett <mike@laurasia.com.au> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Testing file permissions Message-ID: <Pine.LNX.4.10.9911101006440.13100-100000@mail.telestream.com> In-Reply-To: <199911101704.BAA05709@laurasia.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.10.9911101006440.13100-100000>