Date: Thu, 11 Nov 1999 01:04:29 +0800 (WST) From: Michael Kennett <mike@laurasia.com.au> To: freebsd-questions@freebsd.org Subject: Testing file permissions Message-ID: <199911101704.BAA05709@laurasia.com.au>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911101704.BAA05709>