You are on page 1of 2

Program Code:

1)
read -p "Enter file name : " file
[ -w $file ] && W="Write = yes" || W="Write = No"
[ -x $file ] && X="Execute = yes" || X="Execute = No"
[ -r $file ] && R="Read = yes" || R="Read = No"
echo "$file permissions"
echo "$W"
echo "$R"
echo "$X"
echo "Executed By Prathmesh Pote"

Exercise:
1)
read -p "Enter name of the directory: " directory
echo "======================================"
if [ ! -d $directory ]
then
echo "Directory does not exist"
else
count=0
echo "Files with executable rights are"
for i in $(find $directory -type f -perm +rwx)
do
echo " $i"
count=$((count+1))
done
if [ $count -eq 0 ]
then
echo "No files found with executable rights"
else
echo "Total Number of Files:
$count"
fi
fi
echo "Executed By Prathmesh Pote"
2)
read -p "Enter name of the directory: " directory
echo "======================================"
if [ ! -d $directory ]
then
echo "Directory does not
exist"
else
count=0
echo "Files with RWX rights
are"
for i in $(find $directory -type f -
perm +rwx)
do
echo " $i"
count=$((count+1))
done
if [ $count -eq 0 ]
then
echo "No files found with Read, Write and Executable rights"
else
echo "Total Number of Files: $count"
fi fi
echo "Executed By Prathmesh Pote"

3)
read -p "Enter name of file: " f
if [ -e $f ];
then
echo "File Exists!"
elif [ ! -e $f ]; then echo "File does not
Exist" && exit
fi
if [ -w $f ] && [ -r $f ]; then
chmod 777 $f
echo "Changed File Permissions
for filename - $f"
fi
echo "Executed By Prathmesh Pote"

You might also like