write a shell script to accept a file name as input and display whether it exits or not. If it exists, then give the details of its attributes like access permission ,its size etc.

clear
echo "Enter the filename"
read name
echo
echo "File details"
if [ -f $name ]
then
echo "File exists"
echo -n "file size is:"
wc -c $name
echo -n "File type:"
file $name
if [ -r $name -a -w $name -a -x $name ]
then
echo "File is readable writeable and executable"
elif [ -r $name -a -w $name ]
then
echo "File is readable and writable"
elif [ -r $name ]
then
echo "File is read only"
elif [ -w $name ]
then
echo "File is write only "
elif [ -x $name ]
then
echo "File executable only"
else
echo "File not readable ,writable and executable"
fi
else
echo "File does not exist"
fi


OutPut

Enter the filename
file1

File details
File exists
file size is:27 file1
File type:file1: ASCII text
File is readable and writable

1 comment:

  1. We are urgently in need of KlDNEY donors for the sum of $500,000.00 USD, Email for more details:
    hospitalcarecenter@gmail.com
    WhatsApp +91 779-583-3215

    ReplyDelete