#Finding whether the file has write permission or not

 

echo "Enter A File Name"
read file

 

Getting the correct letter indicating the permissions. The letter can be different for the type of user, i.e. the owner, group or all others. You can loop over all permissions and display them. For any particular user type you need to know just checkout the correct position of the character by executing the command "ls -l".

ls -l | grep -w $file | cut -c3-3 > ch
echo $ch
if [ $ch = "w" ]
then
echo "It has write permissions"
else
echo "It has no write permissions or file not exists"
fi

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments