Showing posts with label File access permission. Show all posts
Showing posts with label File access permission. Show all posts

Friday 30 March 2018

Shell script to check whether file is executable, readable and writeable

#Check access permission of the given file
echo "Enter file name: \c"
read file
if [ -e $file ]
then
    echo "'$file' is"
    if [ -x $file ]
    then
       echo "   executable"
    fi
    if [ -r $file ]
    then
       echo "    readable"
    fi
    if [ -w $file ]
    then
       echo "    writeable"
    fi
    if [ -r $file -a -w $file ]
    then
       echo "     both readable and writeable"
    fi
else
    echo "'$file' does not exist"
fi




OUTPUT
csc@csc-SVE1513CYNB ~ $ sh ftesh.sh
Enter file name: a.out
'a.out' is
   executable
    readable
    writeable
     both readable and writeable