Check to file permissions

If, for some reason, you’re not allowed to see the permissions of a file, or you don’t understand the rw-rwx-x format, you can use the following script :

#!/bin/bash

echo -n "Enter file name : "
read file

# find out if file has write permission or not
[ -w $file ] && W="Write = yes" || W="Write = No"
# find out if file has excute permission or not
[ -x $file ] && X="Execute = yes" || X="Execute = No"
# find out if file has read permission or not
[ -r $file ] && R="Read = yes" || R="Read = No"
echo "$file's permissions, as follows : "
echo "$W"
echo "$R"
echo "$X"

The script source is originally taken from cybercity, I’ve changed it a little bit.
Here is a sample report :

[unixgate@unix.com ~]$ ./filePerms.sh
Enter file name : template.doc
template.doc's permissions, as follows :
Write = yes
Read = yes
Execute = No

Published in: on April 23, 2008 at 9:18 am Leave a Comment

The URI to TrackBack this entry is: http://unixgate.wordpress.com/2008/04/23/check-to-file-permissions/trackback/

RSS feed for comments on this post.

Leave a Comment