Saturday, March 10, 2018

Search and find a file in current working directory and it's subdirectories recursively and print it's characteristics using shell script,Linux Teacher Sourav,Kolkata 09748184075

#!/bin/sh


 if [ $# -ne 1 ]; then
 echo "Usage: filechecker filename"
 echo " Will show various attributes of the file given."
exit 255
fi


file_count=$(find . -name $1 | wc -l)
#echo $file_count

echo   $1

if [ "$file_count" -gt 1 ]; then
echo " has multiple version exists in the current directory and it's subdirectories,exiting."
# Leave script now
exit 2
fi

if [ "$file_count" -eq 0 ]; then
 echo " does not exist,exiting."
 exit 1

# Leave script now
fi




if [ -f $1 ] ; then
echo is a file.
 elif [ -d $1 ] ; then
 echo is a directory.

fi

if [ -x $1 ] ; then
echo Is executable.
fi

 if [ -r $1 ] ; then
 echo Is readable.



else
echo Is not readable.
fi

 if [ -w $1 ] ; then
 echo Is writable.

fi






if [ -s $1 ] ; then
echo Is not empty.
else
echo Is empty.
fi


exit 0

No comments:

Post a Comment