Question:
How to check whether the file has read, write and execute permissions
Answer:
#!/usr/bin/bash
file=“/home/kalam/file.text”
## checking for write permissions
if [ -r $file ]
then
echo “File has read access”
else
echo “File does not have read access”
fi
## checking for write permissions
if [ -w $file ]
then
echo “File has write permission”
else
echo “File does not have write permission”
fi
## checking for execute permission
if [ -x $file ]
then
echo “File has execute permissions”
else
echo “File does not have execute permission”
fi
No comments:
Post a Comment